jquery - Spring MVC - ajax integration pageContext.request.contextPath not working -


i trying pass data controller using ajax. there problem url property think. when clicked buttonhello, ajax working in error fuction, er parameter returns "not found".

i think wrong url property because controller class not called. tried other options '/memorize/result/helloajax', etc. value of ${pagecontext.request.contextpath} /springcrud

my ajax

$(document).ready(function() {     $('#buttonhello').click(function(){         $.ajax({             type : 'post',             url : '${pagecontext.request.contextpath}/memorize/result/helloajax',             success : function(data) {                 $('.result').html(data);             },             error:function(data,status,er) {                  alert("error: "+data+" status: "+status+" er:"+er);             }         })     }); }); 

login.jsp

<%@ page language="java" contenttype="text/html; charset=utf-8"     pageencoding="utf-8"%> <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%> <%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>  <!doctype html public "-//w3c//dtd html 4.01 transitional//en" "http://www.w3.org/tr/html4/loose.dtd"> <html> <head>  <script src="<c:url value="/resources/js/jquery-1.11.3.min.js" />"></script> <script src="<c:url value="/resources/js/main.js" />"></script>  <title>login page</title> </head>  <input type="button" value="hello" id="buttonhello"> <div id="result"></div> </html> 

resultcontroller:

@controller @requestmapping(value = "/result") public class resultcontroller {      @requestmapping(value ="/helloajax", method = requestmethod.get)     @responsebody     public string hello(){         return "index";     }      @requestmapping(value ="/helloajax", method = requestmethod.post)     @responsebody     public string helloajax(){         return "hello ajax";     } } 

and web.xml

<?xml version="1.0" encoding="utf-8"?>  <web-app id="webapp_id" version="2.4">      <servlet>         <servlet-name>springcrud</servlet-name>         <servlet-class>             org.springframework.web.servlet.dispatcherservlet         </servlet-class>                          <load-on-startup>1</load-on-startup>     </servlet>     <servlet-mapping>         <servlet-name>springcrud</servlet-name>         <url-pattern>/memorize/*</url-pattern>     </servlet-mapping>      <welcome-file-list>         <welcome-file>index.jsp</welcome-file>     </welcome-file-list>      <context-param>         <param-name>contextconfiglocation</param-name>         <param-value>/web-inf/springcrud-servlet.xml</param-value>     </context-param>      <listener>         <listener-class>org.springframework.web.context.contextloaderlistener         </listener-class>     </listener> </web-app> 


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -