我经历了类似的问题,但无法弄清楚为什么我的代码不起作用。请指出我的代码中有什么错误。问题是 jquery ajax 调用没有到达 spring mvc 控制器
我正在使用 Spring 3.2 和 jackson 1.9
QuestionnaireController.java
@Controller
public class QuestionnaireController {
public QuestionnaireController()
{
super();
}
@RequestMapping(value="/getQnrList.do")
public @ResponseBody Message getMessage(@RequestParam String inputMessage)
{
Message message = new Message();
message.setMessage("I was sent the message : " + inputMessage + " : so I returned.");
return message;
}
}
问卷列表.jsp
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
<script type="text/javascript" src="scripts/jquery-1.6.2.js"></script>
<script type="text/javascript" src="scripts/jquery-ui-1.8.16.custom.min.js"></script>
<script type="text/javascript" src="scripts/json.min.js"></script>
<script type="text/javascript">
function queClick()
{
$.ajax({
url:"getQnrList.do",
method: "GET",
dataType: "json",
contentType: 'application/json',
data: {inputMessage : 'hello'},
success: function()
{
alert("hola");
},
error: function(jqXHR, textStatus, errorThrown) {
alert("error:" + textStatus + " - exception:" + errorThrown);
}
});
}
</script>
</head>
<body>
<p>Questionnaire test</p>
<input type="button" value="Get Questionnaire!" onClick="queClick()">
</body>
</html>
类路径上的 jar 文件
<classpathentry kind="lib" path="D:/Questionnaire1.0 libs/commons-fileupload-1.2.jar"/>
<classpathentry kind="lib" path="D:/Questionnaire1.0 libs/commons-io-1.4.jar"/>
<classpathentry kind="lib" path="D:/Questionnaire1.0 libs/commons-lang3-3.0.1.jar"/>
<classpathentry kind="lib" path="D:/Questionnaire1.0 libs/commons-logging-1.1.1.jar"/>
<classpathentry kind="lib" path="D:/Questionnaire1.0 libs/jackson-core-asl-1.9.11.jar"/>
<classpathentry kind="lib" path="D:/Questionnaire1.0 libs/jackson-mapper-asl-1.9.11.jar"/>
<classpathentry kind="lib" path="D:/Questionnaire1.0 libs/jstl-1.2.jar"/>
<classpathentry kind="lib" path="D:/Questionnaire1.0 libs/log4j-1.2.15.jar"/>
<classpathentry kind="lib" path="D:/Questionnaire1.0 libs/mongo-2.10.1.jar"/>
<classpathentry kind="lib" path="D:/Questionnaire1.0 libs/servlet-api.jar"/>
<classpathentry kind="lib" path="D:/Questionnaire1.0 libs/slf4j-api-1.7.1.jar"/>
<classpathentry kind="lib" path="D:/Questionnaire1.0 libs/slf4j-simple-1.7.1.jar"/>
<classpathentry kind="lib" path="D:/Questionnaire1.0 libs/spring-aop-3.2.1.RELEASE.jar"/>
<classpathentry kind="lib" path="D:/Questionnaire1.0 libs/spring-beans-3.2.1.RELEASE.jar"/>
<classpathentry kind="lib" path="D:/Questionnaire1.0 libs/spring-context-3.2.1.RELEASE.jar"/>
<classpathentry kind="lib" path="D:/Questionnaire1.0 libs/spring-context-support-3.2.1.RELEASE.jar"/>
<classpathentry kind="lib" path="D:/Questionnaire1.0 libs/spring-core-3.2.1.RELEASE.jar"/>
<classpathentry kind="lib" path="D:/Questionnaire1.0 libs/spring-data-commons-core-1.4.0.RELEASE.jar"/>
<classpathentry kind="lib" path="D:/Questionnaire1.0 libs/spring-data-mongodb-1.1.0.RC1.jar"/>
<classpathentry kind="lib" path="D:/Questionnaire1.0 libs/spring-data-mongodb-cross-store-1.1.0.RC1.jar"/>
<classpathentry kind="lib" path="D:/Questionnaire1.0 libs/spring-data-mongodb-log4j-1.1.0.RC1.jar"/>
<classpathentry kind="lib" path="D:/Questionnaire1.0 libs/spring-expression-3.2.1.RELEASE.jar"/>
<classpathentry kind="lib" path="D:/Questionnaire1.0 libs/spring-tx-3.2.1.RELEASE.jar"/>
<classpathentry kind="lib" path="D:/Questionnaire1.0 libs/spring-web-3.2.1.RELEASE.jar"/>
<classpathentry kind="lib" path="D:/Questionnaire1.0 libs/spring-webmvc-3.2.1.RELEASE.jar"/>
<classpathentry kind="output" path="build/classes"/>
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web- app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>QuestionnaireTEST</display-name>
<welcome-file-list>
<welcome-file>questionnaireList.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>qnr</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>qnr</servlet-name>
<url-pattern>/Questionnaire/*</url-pattern>
</servlet-mapping>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/rf_applicationContext.xml
</param-value>
</context-param>
</web-app>
* rf_applicationContext.xml*
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans">
<context:annotation-config></context:annotation-config>
<context:component-scan base-package="com.ref"></context:component-scan>
<mvc:annotation-driven></mvc:annotation-driven>
<context:property-placeholder location="classpath:config.properties"></context:property- placeholder>
<import resource="rf_spring-data.xml" />
</beans>
萤火虫错误讯息
404 未找到 -http://localhost:8080/Questionnaire/getQnrList.do? {%22inputMessage%22:%22hello%22}"
我无法找出错误在哪里