maven html css 路径,Maven——spring mvc加载js css静态资源文件

之前试过和,都不管用。经过尝试采用了下面的方法,加载成功。

首先是目录结构:

6c2e3bccfc9d23c0fdd115fc5771507c.png

common-js.jsp是我为了避免重复引用静态资源而写的通用的jsp页面。在common-js.jsp中引入静态资源,其他的jsp页面只需要适用引入common-js.jsp即可适用静态资源而不需要在每个jsp页面都重复编写加载静态资源的代码。

下面是common-js.jsp的代码:

淘淘商城后台管理系统

商品管理

新增商品

查询商品

规格参数

网站内容管理

内容分类管理

内容管理上面是需要引入common-js.jsp的index.jsp页面的代码。在和标签之间加上这句话:  注意,common-js.jsp是和引入它的jsp放在WEB-INF下的,也必须放在WEB-INF下,否则会加载不到!

放在web-app下加载不到common-js.jsp的错误如下:

javax.servlet.ServletException: File "/WEB-INF/jsps/common-js.jsp" not found

at org.apache.jasper.servlet.JspServlet.handleMissingResource(JspServlet.java:412)

at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:379)

at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)

at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:749)

at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:605)

at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:544)

at org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary.java:954)

at org.apache.jsp.WEB_002dINF.jsps.index_jsp._jspService(index_jsp.java:80)

at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)

at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)

at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)

at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)

at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)

at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:749)

at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:487)

at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:412)

at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:339)

at org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:209)

at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:266)

at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1225)

at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1012)

at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:959)

at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:876)

at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:931)

at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:822)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)

at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:807)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)

at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)

at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)

at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:108)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)

at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)

at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)

at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)

at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)

at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)

at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)

at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)

at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)

at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041)

at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603)

at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)

at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)

at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)

at java.lang.Thread.run(Thread.java:722)

28454ef8f844e1f5302f6bcd79aaecf5.png

因此common-js.jsp必须也放在WEB-INF下。

下面是样式加载成功的效果:

4ef23f580107519a62a69709b8d6e58c.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
>