Springmvc+shiro Project static resources cannot be accessed: Failed to load resource:the Server responded with a status of 404

Source: Internet
Author: User

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 ...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.