struts中的重定向转发功能配置文件的撰写
Posted terlong
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了struts中的重定向转发功能配置文件的撰写相关的知识,希望对你有一定的参考价值。
//Demo1Action.java
package com.struts.a_result; import com.opensymphony.xwork2.ActionSupport; public class Demo1Action extends ActionSupport { @Override public String execute() throws Exception { return "SUCCESS"; } }
//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> <!-- 可配置的常量 --> <!-- i18n:国际化 解决post的提交乱码和输出中文乱码 --> <constant name="struts.i18n.encoding" value="UTF-8"></constant> <!-- 指定反问action时的后缀名 http://localhost:8080/Struts2_test1/hello/HelloAction.xhtml --> <constant name="struts.action.extension" value="action"></constant> <!-- 指定struts2是否以开发模式运行 1.热加载主配置.(不需要重启即可生效) 2.提供更多错误信息输出,方便开发时的调试 --> <constant name="struts.devMode" value="true"></constant> <package name="SSDA1" namespace="/" extends="struts-default" > <action name="Demo1Action" class="com.struts.a_result.Demo1Action" method="execute" > <result name="SUCCESS" type="dispatcher" >/hello.jsp</result><!-- type="dispatcher" 默认为转发 --> </action> <!-- 重定向 --> <action name="Demo2Action" class="com.struts.a_result.Demo2Action" method="execute" > <result name="SUCCESS" type="redirect" >/hello.jsp</result><!-- type="dispatcher" 默认为转发 --> </action> <!-- 重定向到Action --> <action name="Demo3Action" class="com.struts.a_result.Demo3Action" method="execute" > <result name="SUCCESS" type="redirectAction"> <!-- action的名字 --> <param name="actionName">Demo1Action</param> <!-- action所在的命名空间 --> <param name="namespace">/</param> </result> </action> </package> <!-- <include file=""></include>com/struts2/b_dynamic/struts.xml --> </struts>
以上是关于struts中的重定向转发功能配置文件的撰写的主要内容,如果未能解决你的问题,请参考以下文章