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