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.