Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
jquery ajax调用未到达spring mvc控制器_Spring - Fatal编程技术网

jquery ajax调用未到达spring mvc控制器

jquery ajax调用未到达spring mvc控制器,spring,Spring,我也遇到过类似的问题,但无法找出代码不起作用的原因。请指出我的代码中有什么错误。问题是jquery ajax调用没有到达spring mvc控制器 我正在使用 Spring 3.2和jackson 1.9 QuestionnaireController.java questionnaireList.jsp 在此处插入标题 函数queClick() { $.ajax({ url:“getQnrList.do”, 方法:“获取”, 数据类型:“json”, contentType:'应用程序/js

我也遇到过类似的问题,但无法找出代码不起作用的原因。请指出我的代码中有什么错误。问题是jquery ajax调用没有到达spring mvc控制器

我正在使用 Spring 3.2和jackson 1.9

QuestionnaireController.java

questionnaireList.jsp


在此处插入标题
函数queClick()
{
$.ajax({
url:“getQnrList.do”,
方法:“获取”,
数据类型:“json”,
contentType:'应用程序/json',
数据:{inputMessage:'hello'},
成功:函数()
{
警报(“hola”);
},
错误:函数(jqXHR、textStatus、errorshown){
警报(“错误:+textStatus+”-异常:+ERRORSHORN);
}
}); 
}
问卷测验

类路径上的jar文件


web.xml


问卷再测试
questionnaireList.jsp
qnr
org.springframework.web.servlet.DispatcherServlet
1.
qnr
/问卷调查/*
org.springframework.web.context.ContextLoaderListener
上下文配置位置
/WEB-INF/rf_applicationContext.xml
*rf\u 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>

FireBug错误消息

404未找到-
http://localhost:8080/Questionnaire/getQnrList.do? {%22inputMessage%22:%22hello%22}“


我无法找到错误所在

请尝试将url设置为此,然后查看:

url: "http://localhost:8080/Questionnaire/getQnrList.do",

可能url不正确。

请尝试将url设置为此,然后查看:

url: "http://localhost:8080/Questionnaire/getQnrList.do",

可能url不正确。

问题是您没有url模式。请在web.xml中执行

加上这个

  <servlet-mapping>
<servlet-name>qnr</servlet-name>
<url-pattern>*.do</url-pattern>
  </servlet-mapping>

qnr
*.做

同样,您的success函数不会被调用,因为该函数没有参数将您的
success:function()
更改为
success:function(data)
问题是您没有url模式。请在web.xml中执行

加上这个

  <servlet-mapping>
<servlet-name>qnr</servlet-name>
<url-pattern>*.do</url-pattern>
  </servlet-mapping>

qnr
*.做

同样,您的success函数不会被调用,因为该函数没有参数将您的
success:function()
更改为
success:function(data)

要解决此问题,您可以做的第一件事是验证dispatcher servlet文件,以确保url映射等参数


除此之外,您可以尝试在@Controller之后提供@RequestMapping,并在控制器中编写一个带有一些日志项的小GET方法,查看ajax调用是否到达控制器(如果不是控制器中的预期方法)。确认后,您将更好地了解问题的根本原因。

解决此问题的第一件事是验证dispatcher servlet文件,以确保url映射等参数


除此之外,您可以尝试在@Controller之后提供@RequestMapping,并在控制器中编写一个带有一些日志项的小GET方法,查看ajax调用是否到达控制器(如果不是控制器中的预期方法)。一旦您确认您将更好地了解问题的根本原因。

调查问卷
您的上下文修补程序吗?服务器日志上说了什么?QuestionnaireController.java是默认包中的还是com.ref中的?您能在没有ajax调用的情况下访问页面吗?只需将URL指向
http://localhost:8080/Questionnaire/getQnrList.do
并查看是否可以访问该页面。如果不能,则为配置problem@PhD我无法访问该页面。是的,这是配置问题,但无法找到。是的,调查问卷是上下文路径。QuestionnaireController.java在com.ref包中。是
调查问卷
您的上下文修补程序吗?什么服务器日志是否显示?QuestionnaireController.java是在默认包中还是在com.ref中?您可以在没有ajax调用的情况下访问页面吗?只需将URL指向
http://localhost:8080/Questionnaire/getQnrList.do
,看看您是否能访问该页面。如果不能,则为配置problem@PhD我够不着那一页。你呢这是配置问题,但无法找到它。是的,调查问卷是上下文路径。QuestionnaireController.java在com.ref包中。是的,也尝试过,但没有解决。应用程序上下文是调查问卷,@requestMapping是/getQnrList.do,但无法找出错误。是的,也尝试过,没有解决。应用程序上下文是问卷,@requestMapping是/getQnrList.do,但无法找出错误。非常感谢它的工作!!并且为我的愚蠢感到抱歉,我应该已经发现映射是不正确的。再次,您的成功函数将不会被调用,因为该函数没有参数更改您的成功:函数()成功:函数(数据)。如果成功,请接受答案谢谢!为我的愚蠢感到抱歉,我应该知道映射是不正确的。再次,由于函数没有参数,请将success:function()更改为success:function(数据)。如果成功,请接受答案
url: "http://localhost:8080/Questionnaire/getQnrList.do",
  <servlet-mapping>
<servlet-name>qnr</servlet-name>
<url-pattern>*.do</url-pattern>
  </servlet-mapping>