为了使Action与页面端相互认识
使得提交的表单由地址action可以转到相应的类中进行处理
必不可少的要配置相应的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>
<constant name="struts.custom.i18n.resources" value="message"></constant>
<!-- 设置编码格式为GBK,防止乱码-->
<constant name="struts.i18n.encoding" value="gbk"></constant>
<!-- 设置临时的文件存储路径-->
<constant name="struts.multipart.saveDir" value="d:/"></constant>
<package name="struts2" extends="struts-default">
<interceptors>
<interceptor name="myInterceptor" class="com.test.interceptor.MyInterceptor">
<param name="hello">world</param>
</interceptor>
<interceptor name="myInterceptor2" class="com.test.interceptor.MyInterceptor2">
</interceptor>
<interceptor name="myInterceptor3" class="com.test.interceptor.MyInterceptor3">
</interceptor>
<interceptor name="auth" class="com.test.interceptor.AutInterceptor"></interceptor>
<interceptor-stack name="myStack">
<interceptor-ref name="myInterceptor"></interceptor-ref>
<interceptor-ref name="myInterceptor2"></interceptor-ref>
<interceptor-ref name="defaultStack"></interceptor-ref>
</interceptor-stack>
</interceptors>
<default-action-ref name="myStack"></default-action-ref>
<global-results>
<result name="login">/login2.jsp</result>
</global-results>
<action name="login" class="com.test.action.LoginAction">
<result name="input">/login2.jsp</result>
<result name="failer">/login2.jsp</result>
<result name="success">/register2.jsp</result>
</action>
<action name="pointCon"
class="com.test.action.PointAction">
<result name="success">/output.jsp</result>
</action>
<action name="register"
class="com.test.action.RegisterAction" method="abc">
<result name="success">/success.jsp</result>
<result name="input">/register2.jsp</result>
<!--
<interceptor-ref name="myStack"></interceptor-ref>
-->
<!-- 方法过滤拦截器要放在前面,否则不会生效 -->
<!--
<interceptor-ref name="myInterceptor3">
<param name="excludeMethods">abc</param>
<param name="includeMethods">abc,execute</param>
</interceptor-ref>
-->
<interceptor-ref name="auth"></interceptor-ref>
<interceptor-ref name="defaultStack"></interceptor-ref>
</action>
<action name="upload" class="com.test.action.UploadAction">
<result name="success">/UploadResult.jsp</result>
<result name="input">/upload/supload.jsp</result>
<interceptor-ref name="fileUpload">
<param name="maximumSize">409600</param>
<param name="allowedTypes">text/html</param>
</interceptor-ref>
<interceptor-ref name="defaultStack"></interceptor-ref>
</action>
<!-- 此段落为文件下载所需要的-->
<action name="download" class="com.test.action.DownloadAction">
<!-- 必须将类型设置为stream的,否则不会识别下载-->
<result name="success" type="stream">
<param name="contentType">text/html</param>
<!-- filename属性由HTTP协议所要求,不可随意更改,同时aa.doc为设置的下载文件名-->
<param name="contentDisposition">filename="aa.doc"</param>
<param name="inputName">downloadStream</param>
</result>
</action>
</package>
</struts>