SpringMVC+shiro项目静态资源不能访问:Failed to load resource: the server responded with a status of 404
2018-01-24 22:52
736 查看
一、问题描述
最近一直在学开源项目,然后在网上找个了SpringMVC+shiro的项目,然后导入到eclipse中,一运行,前用页面报错如下,静态文件全都找不到:
Failed to load resource: the server responded with a status of 404 (Not Found)
项目结构如下:
Shiro配置文件如下:
<property name="filterChainDefinitions">
<value>
/page/login/** = anon
/statics/** = anon
/api/** = anon
/login.html = anon
/index_bak.html = anon
/sys/login = anon
/captcha.jpg = anon
/** = authc
</value>
</property>
二、解决方法
出现这个错误,无非就两种原因引起的:
1.SpringMVC拦截了静态资源
2.shiro的拦截器配置错了
3.页面中路径写错了
这里采用了排除法来进行测试,首先,把shiro拦截器去掉,不让他起作用,然后测试,发现也不能访问,这样就可以排除是shiro的问题了,如果SpringMVC能访问静态资源,而Shiro不能,那就说明是shiro的问题,还有中测试方式就是之后访问报404的js或css看能不能访问!!
(一)、如果SpringMVC烂拦截了的话可以做如下设置,使用默认的静态资源处理Servlet处理静态资源(涉及spring-mvc.xml, web.xml),在spring-mvc.xml中启用默认Servlet
<mvc:default-servlet-handler/>
在web.xml中增加对静态资源的处理
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.js</url-pattern>
<url-pattern>*.css</url-pattern>
<url-pattern>/assets/*"</url-pattern>
<url-pattern>/images/*</url-pattern>
</servlet-mapping>
(二)、而如果是shiro的话,基本上就是拦截器写错了,多注意下路径什么的。
(三)、我这边的问题就出在这里。。由于他页面用的是html而不是jsp,所以发现他直接写的是相对路径。。。
如果是jsp页面倒好解决,通过引入el表达式来解决
${pageContext.request.contextPath}/xxx
但在html页面中不能用,直接显示出来,并没有解析。。最后只能通过修改在tomcat中发布项目名来解决,也就是说去除项目名直接:localhost:8080/ 来访问项目就行了。。。
在eclipse中把path直接设置为空就行了。。
最近一直在学开源项目,然后在网上找个了SpringMVC+shiro的项目,然后导入到eclipse中,一运行,前用页面报错如下,静态文件全都找不到:
Failed to load resource: the server responded with a status of 404 (Not Found)
项目结构如下:
Shiro配置文件如下:
<property name="filterChainDefinitions">
<value>
/page/login/** = anon
/statics/** = anon
/api/** = anon
/login.html = anon
/index_bak.html = anon
/sys/login = anon
/captcha.jpg = anon
/** = authc
</value>
</property>
二、解决方法
出现这个错误,无非就两种原因引起的:
1.SpringMVC拦截了静态资源
2.shiro的拦截器配置错了
3.页面中路径写错了
这里采用了排除法来进行测试,首先,把shiro拦截器去掉,不让他起作用,然后测试,发现也不能访问,这样就可以排除是shiro的问题了,如果SpringMVC能访问静态资源,而Shiro不能,那就说明是shiro的问题,还有中测试方式就是之后访问报404的js或css看能不能访问!!
(一)、如果SpringMVC烂拦截了的话可以做如下设置,使用默认的静态资源处理Servlet处理静态资源(涉及spring-mvc.xml, web.xml),在spring-mvc.xml中启用默认Servlet
<mvc:default-servlet-handler/>
在web.xml中增加对静态资源的处理
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.js</url-pattern>
<url-pattern>*.css</url-pattern>
<url-pattern>/assets/*"</url-pattern>
<url-pattern>/images/*</url-pattern>
</servlet-mapping>
(二)、而如果是shiro的话,基本上就是拦截器写错了,多注意下路径什么的。
(三)、我这边的问题就出在这里。。由于他页面用的是html而不是jsp,所以发现他直接写的是相对路径。。。
如果是jsp页面倒好解决,通过引入el表达式来解决
${pageContext.request.contextPath}/xxx
但在html页面中不能用,直接显示出来,并没有解析。。最后只能通过修改在tomcat中发布项目名来解决,也就是说去除项目名直接:localhost:8080/ 来访问项目就行了。。。
在eclipse中把path直接设置为空就行了。。
相关文章推荐
- (springmvc)页面找不到静态资源文件Failed to load resource: the server responded with a status of 404 (Not Found)
- springmvc Failed to load resource: the server responded with a status of 404 (Not Found)
- SrpingMVC==>Failed to load resource: the server responded with a status of 404(Not Found)
- ripple Failed to load resource: the server responded with a status of 404 (Not Found)
- 好困出来的bugFailed to load resource: the server responded with a status of 404 (Not Found)
- Failed to load resource: the server responded with a status of 404 (Not Found)
- Failed to load resource: the server responded with a status of 404 (Not Found)
- Failed to load resource: the server responded with a status of 404
- jquery:Failed to load resource: the server responded with a status of 404 (Not Found)
- Failed to load resource: the server responded with a status of 404 (Not Foun
- ajax 报错 400 (Failed to load resource: the server responded with a status of 400 (Bad Request))
- Failed to load resource: the server responded with a status of 400 (Bad Request)
- 上传文件失败 Failed to load resource: the server responded with a status of 413 (Request Entity Too Large)
- Failed to load resource: the server responded with a status of 504 (Gateway Time-out)
- Failed to load resource: the server responded with a status of 413 (Request Entity Too Large)
- SharePoint Debug - Failed to load resource: the server responded with a status of 500
- Failed to load resource: the server responded with a status of 406 (Not Acceptable)
- 关于使用springmvc时Failed to load resource: the server responded with a status of 400 (Bad Request)错误可能原因
- failed to load resource the server responded with a status of 500 (internal server error)
- Failed to load resource: the server responded with a status of 504 (Gateway Time-out)