Invalid resources such as css and js in struts2 are related to non-path issues (for beginners)

Source: Internet
Author: User

A small Strust2 example

Then I found that css, js, and images could not be used. I found that I could not access these resources (404 error) under debugger. That is a good example. I should look at the pictures in the book at least.

It is found that the filter problem in web. xml is as follows:

Web. xml

<?xml version="1.0" encoding="UTF-8"?><web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"         version="3.1">    <filter>        <filter-name>struts2</filter-name>        <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>    </filter>    <filter-mapping>        <filter-name>struts2</filter-name>        <url-pattern>/*</url-pattern>    </filter-mapping><welcome-file-list>    <welcome-file>index.jsp</welcome-file>    </welcome-file-list></web-app>

The red part of the code filters out All accesses. Isn't access to css, js, and other resources filtered out? But the example in that book is written in this way. Is Mao !!. Mom.

The strust. xml file only has an action.

Go to github and check out the complete project. After a long time, I found that a similar project has applied Strust2 and css and other resource files. Then the web. xml file is exactly the same as mine, but note that the Strust. xml file has a special feature. Is the following line:

<constant name="struts.action.excludePattern" value="/static/.*?" /><!-- default locale -->
 

Static files are the places where css, js, images, and other resources are placed. The Code is also annotated.

This is the case with mom.

Add this line of code under the <Strust> label in strust. xml (change static to the folder in the resource file under the root folder)

Now all the resource files under this file shelf can be accessed!

But remember that the reference path is preferably an absolute path. This is an old problem.

 

 

 

 

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.