I. Description of the problem
have been learning open source projects, and then find a Springmvc+shiro on the Internet project, and then import into Eclipse, a run, the previous page with the error below, static files are not found:
Failed to load Resource:the Server responded and a status of 404 (Not Found)
The project structure is as follows:
The Shiro configuration file is as follows:
<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>
Ii. Solutions
There are two reasons for this error:
1.SpringMVC intercepts static resources.
2.shiro Interceptor configured incorrectly 3. The path in the page is wrong.
Here uses the elimination method to carry on the test, first, takes off the Shiro interceptor, does not let him function, then tests, discovers also cannot access, thus can eliminate is shiro the question, if SPRINGMVC can access the static resources, but Shiro cannot, that explains is the Shiro question, There are also in the test way is to visit the newspaper 404 JS or CSS to see can visit!!
(a), if Springmvc rotten interception can do the following settings, using the default static resource processing servlet processing static resources (involving Spring-mvc.xml, Web.xml), in Spring-mvc.xml enable the default servlet
<mvc:default-servlet-handler/>
Increasing the processing of static resources in 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>
(b), and if it is Shiro, basically is the interceptor write wrong, pay more attention to the path or something.
(c) My question is here. Since he used HTML instead of JSP, he found that he wrote the relative path directly ...
If the JSP page is resolved, by introducing an El expression to solve
${pagecontext.request.contextpath}/xxx
But in the HTML page can not be used, directly displayed, and did not parse. Finally, only by modifying the project name in Tomcat to solve, that is, to remove the project name directly: localhost:8080/to access the project on the line ...
It's OK to set the path directly to NULL in eclipse ...