Today, I used springMvc + jsp to create a project and found that static resource files are always unavailable from time to time.
Of course, google Baidu found that some of the above methods have been mentioned, so that these static files are not processed by springDispatcher, and the idea of using tomcat default servlet to process
After doing so, I found it was okay.
A
@ RequestMapping (value = "/cardtool", method = RequestMethod. GET)
Public String cardTool (){
Return "/cardtool ";
}
Find cardtool. jsp
The following are static resources referenced on this jsp interface.
<Script src = "assets/js/card. js" type = "text/javascript"> </script>
<Script src = "assets/js/json. js" type = "text/javascript"> </script>
Http: // 127.0.0.1: 8010/project name/assets/js/card. js
So I want to try to change the value of RequestMapping.
Code changes
B
@ RequestMapping (value = "/cardtool/test/dev", method = RequestMethod. GET)
Public String cardTool (){
Return "/cardtool ";
}
I cannot find any strange static files in my requests. Why are these files introduced by relative paths?
I saw Error 404.
Http: // 127.0.0.1: 8010/project name/cardtool/assets/js/card. js
How can I find a cardtool?
So try
<Script src = "../assets/js/json. js" type = "text/javascript"> </script>
Yes, but an error is returned when A is used.
This is the beginning and end of the story. How does spring get rid of my webapp path?
It's better to be sad and helpless. forget to use the jsp tag.
<%
String path = request. getContextPath ();
String basePath = request. getScheme () + ": //" + request. getServerName () + ":" + request. getServerPort () + path + "/";
%>
<Script src = "assets/js/card. js" type = "text/javascript"> </script>
<Script src = "assets/js/json. js" type = "text/javascript"> </script>
After the rows are complete, try the B method for the request. I do not like this method, because it is necessary to execute the basePath code for computing every page, but there is no good solution either.
Hope springMVC can solve this problem early
Paste the core code below so that everyone will not be the same as me.
Web. xml
SpringDispatcher
Org. springframework. web. servlet. DispatcherServlet
ContextConfigLocation
Classpath *:/spring/spring-framework.xml
Classpath: // spring/spring-base.xml
Classpath: // spring/spring-web.xml
2
SpringDispatcher
/
Default
/Assets /*
The jsp page will not be pasted. See the preceding parsing.