[Struts2] 配置Struts2.3.16.3

虽然Struts2 的版本到2.3.16.3了,但是基本配置不变。

和2.1.x一样,首先把必要的jar包拷贝到项目的libs目录。

需要的jar包:

如果不确定用到哪些包,可以先运行Struts源码包里面的几个案例。struts2-blank,struts2-mailreader,struts2-portlet,struts2-rest-showcase,struts2-showcase。然后到该项目的目录下拷贝lib下的jar包即可。还有,配置文件也是一样,如,web.xml和struts.xml。

以struts2-blank为例。

lib:以下是本项目需要的jar包。[注:只是搭建一个简单的Struts2环境而已,基本的请求处理,拦截器什么的都是可以用的,就以下包就可以了]

-rwxrwxrwx  1 gopain  staff   43578 11 23  2013 asm-3.3.jar
-rwxrwxrwx  1 gopain  staff   38275 11 23  2013 asm-commons-3.3.jar
-rwxrwxrwx  1 gopain  staff   21503 11 23  2013 asm-tree-3.3.jar
-rwxrwxrwx  1 gopain  staff   69002  2 19  2014 commons-fileupload-1.3.1.jar
-rwxrwxrwx  1 gopain  staff  173587 11 23  2013 commons-io-2.2.jar
-rwxrwxrwx  1 gopain  staff  315805 11 23  2013 commons-lang3-3.1.jar
-rwxrwxrwx  1 gopain  staff   62050 11 23  2013 commons-logging-1.1.3.jar
-rwxrwxrwx  1 gopain  staff  931168 11 23  2013 freemarker-2.3.19.jar
-rwxrwxrwx  1 gopain  staff  614203 11 23  2013 javassist-3.11.0.GA.jar
-rwxrwxrwx  1 gopain  staff  489884 11 23  2013 log4j-1.2.17.jar
-rwxrwxrwx  1 gopain  staff  227997 11 23  2013 ognl-3.0.6.jar
-rwxrwxrwx  1 gopain  staff  800691  5  2  2014 struts2-core-2.3.16.3.jar
-rwxrwxrwx  1 gopain  staff  654177  5  2  2014 xwork-core-2.3.16.3.jar

然后是配置web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_9" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

    <display-name>Struts Blank</display-name>

    <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.html</welcome-file>
    </welcome-file-list>

</web-app>

web.xml的配置和以前的基本配置是一样的,

然后是struts.xml配置:[注:在classes文件夹下的根目录下]

<?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.enable.DynamicMethodInvocation" value="false" />
    <constant name="struts.devMode" value="true" />

    <package name="default" namespace="/" extends="struts-default">

        <default-action-ref name="index" />

        <global-results>
            <result name="error">/error.jsp</result>
        </global-results>

        <global-exception-mappings>
            <exception-mapping exception="java.lang.Exception" result="error"/>
        </global-exception-mappings>

        <action name="index">
            <result type="redirectAction">
                <param name="actionName">HelloWorld</param>
                <param name="namespace">/example</param>
            </result>
        </action>
    </package>

    <include file="example.xml"/>

    <!-- Add packages here -->

</struts>
 
 
 
 


文件中引入的example.xml文件:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
        "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
        "http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>

    <package name="example" namespace="/example" extends="default">

        <action name="HelloWorld" class="example.HelloWorld">
            <result>/example/HelloWorld.jsp</result>
        </action>

        <action name="Login_*" method="{1}" class="example.Login">
            <result name="input">/example/Login.jsp</result>
            <result type="redirectAction">Menu</result>
        </action>

        <action name="*" class="example.ExampleSupport">
            <result>/example/{1}.jsp</result>
        </action>

        <!-- Add actions here -->
    </package>
</struts>



然后以上配置就可以让struts2工作了。

下一篇具体讲解配置项的原理。

网站war文件下载路径。http://download.csdn.net/detail/gopain/8114857

Done.


你可能感兴趣的:(xml,struts2,web.xml,jar)