[org.springframework.web.servlet.PageNotFound] -No mapping found for HTTP request with URI [/homework/js/jquery-1.7.2.min.js] in DispatcherServlet with name 'SpringMVC'

先上解决方案:对于上面出现的问题,查看了很多相关的博客,论坛。最后实在Spring-mvc.xml这个配置文件里加入了如下两行:

1     <mvc:annotation-driven />
2     <mvc:default-servlet-handler />

问题描述:

由于项目需要Ajax,于是在jsp的head里加入了如下代码:

 1 <script type="text/javascript" src="/homework/js/jquery-1.7.2.min.js"></script>
 2     
 3      <script type="text/javascript">
 4       $(document).ready(function() {
 5         ajaxRequest();
 6       });
 7 
 8       function ajaxRequest() {
 9         $.ajax({
10           url: "http://localhost:8080/homework/file/checkNo",
11           type: "POST",
12           dataType: "json",
13           data: {
14             "stuNo": 2014302580069
15           },
16           async: false,
17           success: function(data) {
18             alert("success");
19             $.each(data, function(index, element) {
20               alert(element.stuNo);
21 
22             });
23           },
24           error: function() {
25             alert("error");
26           }
27         });
28       }
29     </script>

部署项目,打开该JSP,发现该Ajax请求无法执行。

在浏览器里查看发现Jquery库无法加载,报404错误。

一开始按照百度的某一种方法,在Spring-MVC.xml里添加了如下代码,配置了静态资源

<mvc:resources mapping="/js/**" location="/js/" />

然后发现顺利加载了JQuery库,但是其他接口反而无法访问了。又转而去调试了拦截器,经过一下午修改尝试,最终按照上面的结论方法,成功运行Ajax。

 

posted @ 2016-10-22 22:33  qq29oo  阅读(645)  评论(0编辑  收藏  举报