1. 程式人生 > >struts-2.2.3 配置詳解

struts-2.2.3 配置詳解

1、在WEB-INF下面的lib裡面新增下面的jar包

commons-fileupload-1.2.2

commons-io-2.0.1

commons-lang-2.5

commons-logging-1.1.1

freemarker-2.3.16

javassist-3.11.0.ga

ognl-3.0.1

struts2-core-2.2.3

xwork-core-2.2.3

2、WEB-INF下面的web.xml配置

其實只要在web.xml中新增一個filter就行了,web.xml配置如下:

<?xml version="1.0" encoding="UTF-8"?>
       <web-app version="2.5" 
       xmlns="

http://java.sun.com/xml/ns/javaee
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance
       xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
      http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd
">


     <welcome-file-list>
           <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>


   <!-- Struts2 Filter-->
   <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、src下面的struts.xml的配置

<?xml version="1.0" encoding="UTF-8" ?>
      <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
     <struts>
           <package name="struts2" extends="struts-default"  >
               <action name="login" class="com.login.loginAction">
                   <result name="success">/success.jsp</result>
                   <result name="error">/error.jsp</result>  
              </action>
          </package>
    </struts>

注意

如果struts2版本是2.1以前 

web.xml配置過濾器的時候應該是這樣: 

<web-app> 
<filter> 
<filter-name>struts2</filter-name> 
<filter-class>

org.apache.struts2.dispatcher.FilterDispatcher
</filter-class> 
</filter> 
<filter-mapping> 
<filter-name>struts2</filter-name> 
<url-pattern>/*</url-pattern> 
</filter-mapping> 
</web-app> 


如果struts2 版本是2.1以上 

web.xml配置 

<web-app> 
<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>