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.