Struts2通用的action 配置
阿新 • • 發佈:2019-01-23
struts.xml 配置一個<action/>, 如下:
Xml程式碼- <!-- 通用配置 結合了spring,在spring的bean名稱 是registerAction-->
- <actionname="*_*"class="{1}Action"method="{2}">
- <resultname="success">/{1}/success.jsp</result>
- <resultname="input">/{1}/input.jsp</result>
- <result
- <resultname="none">/{1}/none.jsp</result>
- <resultname="login">/login/index.jsp</result>
- <resultname="{2}">/{1}/{2}.jsp</result>
- <resultname="forwardJsp">/{1}/${forwardJsp}</result>
- <resultname="json"type
- </action>
<result name="forwardJsp">/{1}/${forwardJsp}</result> 中的forwardJsp是哪來的? 請看下面的Action(部分)
類名是RegisterAction , 在spring的bean名稱是registerAction
Java程式碼- 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 檔案