Remember a strange problem in intercepting the path of SpringMVC

<!--springmvc中的核心控制器-->
<servlet>
<servlet-name>dispatcherServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:springmvc.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcherServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>

静态资源映射
<mvc: resources mapping = "/ js / **" location = "/ js /"> </ mvc: resources> 

a button click event ajax
the getData function () { 
$ .ajax ({
URL: "/ testAjax",
type: "POST",
contentType: "file application / JSON; charset = UTF-. 8",
Data: '{ "name": "Test", " Age ":} 12 is',
dataType:" JSON ",
Success: function (Data) {
Alert (Data);
},
error: function (Data) {
Alert (" abnormal ")
}
})
}

1. do not initially the method of any changes, click the button did not play should view the page source code, click the js file, jump to below
@RequestMapping (name = "/ testString") 
public String testString (String id, the HttpServletRequest Request) {

// accepted. 1 id
// 2 The user id queries
the User User new new = the User ();
user.setName ( "flower");
user.setAge (. 19);
// domain request into
request.setAttribute ( "User", User);

return "Success";
}

2. * url-pattern changed after .do, click the button will pop up a dialog box: abnormal, view the page source code, click js file js file is accessible to the
3. Then url-pattern to /, click the button dialog box will pop up: data, view the page source code, click to access the js file js file is
4. undo back to its initial state, restart tomcat, normal operation, restarting tomcat again, back to the results of 1, and the / re-enter the delete / no effect, it can only be performed after 2, back to the * .do / valid
5. after the test, as long as the abnormal url-pattern once again changed back / normal operation can

not understand. . . . .

Guess you like

Origin www.cnblogs.com/DSLLMV/p/10992900.html