struts-2.3.31 and struts-2.5.10 introduce jars and configure Web.xml and Struts.xml__web

Source: Internet
Author: User
Tags log4j

nonsense
In struts learning process, many tutorials are used strut-2.3.31, and now the latest is struts-2.5.10, after the upgrade STRUT2 skills will always be a bit of a change. Also thought that as long as the tutorial on the line, did not expect to keep the error, simply can not let people enjoy the fun of knocking code. struts-2.3.31 1. Introducing Jars

Asm-3.3.jar
asm-commons-3.3.jar
asm-tree-3.3.jar
Commons-fileupload-1.3.1.jar
Commons-io-2.2.jar
commons-lang3-3.1.jar
commons-logging-1.1.3.jar
Freemarker-2.3.19.jar
Jarlist.txt
javassist-3.11.0.ga.jar
ognl-3.0.6.jar
Struts2-core-2.3.16.3.jar
Xwork-core-2.3.16.3.jar
2. Web.xml
<?xml version= "1.0" encoding= "UTF-8"?> <web-app xmlns:xsi=
"Http://www.w3.org/2001/XMLSchema-instance" " 
xmlns=" Http://java.sun.com/xml/ns/javaee " 
xsi:schemalocation=" Http://java.sun.com/xml/ns/javaee http ://java.sun.com/xml/ns/javaee/web-app_2_5.xsd " 
version=" 2.5 ">
  <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>
</web-app>
3. Struts.xml
<?xml version= "1.0" encoding= "UTF-8"?> <!
DOCTYPE struts public
    "-//apache Software foundation//dtd struts Configuration 2.3//en"
    "http:// Struts.apache.org/dtds/struts-2.3.dtd ">
<struts>
    <constant name=" Struts.devmode "value=" true "/>
    <!--all action definitions should be placed under package--> <package name=" Crazyit "namespace="   
    /"extends=" Struts-default ">     
        <action name=" * ">
            <result>/WEB-INF/content/{1}.jsp</result>
        </action>
    </package>
</struts>
struts-2.5.10 1. Introduce jar
Asm-5.1.jar
asm-commons-5.1.jar
asm-tree-5.1.jar
Commons-fileupload-1.3.2.jar
Commons-io-2.4.jar
commons-lang3-3.4.jar
commons-logging-1.1.3.jar
Freemarker-2.3.23.jar
Jarlist.txt
javassist-3.20.0-ga.jar
log4j-api-2.7.jar
Ognl-3.1.12.jar
Struts2-core-2.5.10.jar

Compared to the struts-2.3.31,2.5.10 version need to import the basic jar Xwork-core-2.3.16.3.jar, more log4j-api-2.7.jar. Because Xwork-core has been integrated into the struts-core, so here we download struts-2.5.10/lib can't find xwork-core words, but we can use decompression software to open the Struts-core to view the internal files, You can find xwork that were not in the previous version. If there is no Log4j-api-2.7.jar ', if the Web.xml and Struts.xml are configured correctly, the error will be the following:

2. Web.xml

<?xml version= "1.0" encoding= "UTF-8"?> <web-app "id= starter" version= "2.4" xmln s= "Http://java.sun.com/xml/ns/j2ee" xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance" Xsi:schemaloca
        tion= "Http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" > <filter> <filter-name>struts2</filter-name> <!--<filter-class>org.apache.struts2.disp
        Atcher.ng.filter.strutsprepareandexecutefilter</filter-class>--> <!--There are no NG directories in the following path--> <filter-class>org.apache.struts2.dispatcher.filter.strutsprepareandexecutefilter </filter-class> &L t;/filter> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern> ;/*</url-pattern> </filter-mapping> </web-app> 

Careful readers can find a big difference is that 2.5.10 version Configuration <filter-class> Specifies that one ng is missing from the classpath. Yes, there is no mistake, we just open struts2-core-2.5.10.jar to find that there is no subdirectory ng. It is only through the path above that the class Strutsprepareandexecutefilter can be found. If you do not configure the correct path, the following error is reported:

3. Struts.xml

<?xml version= "1.0" encoding= "UTF-8"?> <!
DOCTYPE struts public
    "-//apache Software foundation//dtd struts Configuration 2.5//en"
    "http:// Struts.apache.org/dtds/struts-2.5.dtd ">

<struts>
    <constant name=" Struts.devmode "value=" true "/>
    <!--all action definitions should be placed under package--> <package name=" Crazyit "namespace="   
    /"extends=" Struts-default ">     
        <action name=" * ">
            <result>/WEB-INF/content/{1}.jsp</result>
        </action>
    </package>
</struts>

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.