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> 

    

你可能感兴趣的:(struts,filter,Class,action,login,encoding)