Invalid non-path problem of CSS,JS and other resources in struts2 (novice problem)

Source: Internet
Author: User

A small example of Strust2

And then found Css,js, the picture can not be used, debugger found unable to access these resources (404 error), Mom, that example is clearly possible, at least from the book pictures.

The discovery is a problem with the filter in Web. XML, the code is this:

Xml

<?XML version= "1.0" encoding= "UTF-8"?><Web-appxmlns= "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-pa Ttern> </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 the accesses. This is not even CSS,JS resources such as access to filter out? But the example in that book is written in this way, as everyone writes. For Mao!. Mom, Egg.

The Strust.xml file is just a single action.

Roll on GitHub to see the complete project, find a long time, found a similar project applied Strust2, also applied CSS and other resource files. Then the Web. xml file is exactly the same as mine, but notice that the Strust.xml file has a special place. This is the following line:

<name= "Struts.action.excludePattern"  value= "/static/.*?" /><!--default Locale--

Static files are places where resources such as CSS,JS, pictures, and so on are placed, which are also annotated next to the code.

Mom, the egg was like this.

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

All the resource files that are now located under this file rack can be accessed!

But remember that the reference path is best an absolute path. This is already 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.