struts.xml 配置一个<action/>, 如下:
- <!-- 通用配置 结合了spring,在spring的bean名称 是registerAction-->
- <action name="*_*" class="{1}Action" method="{2}">
- <result name="success">/{1}/success.jsp</result>
- <result name="input">/{1}/input.jsp</result>
- <result name="error">/{1}/error.jsp</result>
- <result name="none">/{1}/none.jsp</result>
- <result name="login">/login/index.jsp</result>
- <result name="{2}">/{1}/{2}.jsp</result>
- <result name="forwardJsp">/{1}/${forwardJsp}</result>
- <result name="json" type="json"></result>
- </action>
<result name="forwardJsp">/{1}/${forwardJsp}</result> 中的forwardJsp是哪来的? 请看下面的Action(部分)
类名是RegisterAction , 在spring的bean名称是registerAction
- protected String forwardJsp = "result.jsp"; //自定义的转发到result.jsp
- public String getForwardJsp()
- {
- return forwardJsp;
- }
- ----------------- 上面的代码 写在ActionBase 类中-------------------
- public String pre()
- {
- //return INPUT; //INPUT是Action接口中定义的 , 转发到 /register/input.jsp
- //return "pre" ; //"pre"是方法名 , 转发到 /register/pre.jsp
- forwardJsp = "ss.jsp"; //自定义转发到哪个JSP文件
- return "forwardJsp";
- }
请求 url 为: http://localhost/register_pre.action 时
会执行pre()方法
转发到 /register/ss.jsp 文件
最后
以上就是听话鞋垫最近收集整理的关于Struts2通用的action 配置的全部内容,更多相关Struts2通用的action内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复