Today, when Springmvc forwarded the page, it was found that the jump page did succeed, but static resources such as JS,CSS did not work:
Control Layer Code:
/** * Forward to view the Culture Program details page @return */ @RequestMapping ("/ 2TrainSchemeDatail ") public String forward2trainschemedetail (@RequestParam ( DefaultValue = "1") String Trainschemeid, model model) { Model.addattribute ("Trainschemeid", Trainschemeid); return "Pages/trainingscheme/trainingscheme"; }
View Parser configuration:
<!--3. View Interpreter - <Beanclass= "Org.springframework.web.servlet.view.InternalResourceViewResolver"> < Propertyname= "prefix"value="/" /> < Propertyname= "suffix"value= ". jsp" /> </Bean>
Effect:
The last analysis is the path problem of JS and CSS: the relative path is used, so the resource cannot be found
Workaround:
In the JSP header plus
< % = Request.getcontextpath (); + " ://" + request.getservername () + ":" + request.getserverport () + path + "/";% >
Change the relative path of the resource file, such as Css,js,img, and the access controller to an absolute path:
<%=basepath%>js/jquery-1.9.1.min.js
-
- The second type (recommended)
JSP sets a variable that records the name of the item: the following ${baseurl} is equivalent to/project name
<%@ taglibURI= "Http://java.sun.com/jsp/jstl/core"prefix= "C"%><%@ taglibURI= "Http://java.sun.com/jsp/jstl/fmt"prefix= "FMT"%><%@ taglibprefix= "FN"URI= "Http://java.sun.com/jsp/jstl/functions"%><C:setvar= "BaseURL"value= "${pagecontext.request.contextpath}"></C:set><Scripttype= "Text/javascript"> <%--torecord Pronect Name (ContextPath=/jwxt)--%>ContextPath= "${pagecontext.request.contextpath}"; </script>
JS and CSS path changed to:
<Linkrel= "stylesheet"href= "${baseurl}/css/font.css"> <Linkrel= "stylesheet"href= "${baseurl}/css/xadmin.css"> <Scripttype= "Text/javascript"src= "${baseurl}/js/jquery.min.js"></Script> <Scripttype= "Text/javascript"src= "${baseurl}/lib/layui/layui.js"CharSet= "Utf-8"></Script> <Scripttype= "Text/javascript"src= "${baseurl}/js/xadmin.js"></Script>
SPRINGMVC controller jump to JSP page css img js etc file does not work not show