Struts2单独配置

//配置Sturts2过滤器

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

 

//配置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.action.extension" value="do,jspx"></constant>

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

          <action name="hello"  class="com.kaishengit.action.HelloAction" method="hello">

               <result name="success">/WEB-INF/views/hello.jsp</result>

                <result name="input"  type="redirectAction">

                    <param  name="actionName">Home</param>

                    <param  name="method">index</param>

               </result>

          </action>

     </package>

</struts> 

struts拦截器

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE struts PUBLIC

"-//Apache Software Foundation//DTD Struts Configuration 2.1.7//EN"

"http://struts.apache.org/dtds/struts-2.1.7.dtd">

 

<struts>

<constant name="struts.action.extension" value="html,action,,"></constant>

<constant name="struts.convention.default.parent.package" value="basicPackage"/>

<package name="basicPackage" extends="convention-default" abstract="true">

<interceptors>

<interceptor name="LoginValidate" class="com.kaishengit.action.interceptor.LoginValidateInterceptor"/>

<interceptor-stack name="myStack">

<interceptor-ref name="defaultStack"/>

<interceptor-ref name="LoginValidate">

<param name="sessionName">staff</param>

<param name="includeName">index,login,,/</param>

</interceptor-ref>

</interceptor-stack>

</interceptors>

<default-interceptor-ref name="myStack"/>

 

<global-results>

<result name="input" type="redirectAction">

<param name="actionName">index</param>

<param name="error">1002</param>

<param name="namespace">/</param>

</result>

</global-results>

</package>

</struts>

你可能感兴趣的:(Struts2 JAVA)