Result Learning Note (ii)-dynamic result set Dynamic Results Be sure not to forget to set the set get method for the saved value of the dynamic result
First part: Code
//frontend <% String context = Request.getcontextpath (); %><! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
//web.xml <struts> <constant name= "Struts.devmode" value= "true"/> <package name= "user" namespace= "/user" exten ds= "Struts-default" > <action name= "User" class= "com.struts2.user.action.UserAction" > <result>${r} </result> </action> </package> </struts>
Class Pack Package Com.struts2.user.action;import Com.opensymphony.xwork2.actionsupport;public class Useraction extends actionsupport {private int type;private string R;public string Getr () {return r;} public void Setr (String r) {THIS.R = R;} public int GetType () {return type;} public void SetType (int type) {this.type = type;} @Overridepublic String Execute () throws Exception {if (type = = 1) r= "/user_success.jsp"; else if (type = = 2) r= "/user_error. JSP "; return" Success ";}}
Part II: Configuration Analysis Web. xml:
Result section:
<result>${r}</result>
Class Package Analysis:
private String R;public string Execute () throws Exception {if (type = = 1) r= "/user_success.jsp"; else if (type = = 2) r= "/use R_error.jsp ";" Return "Success";}
There are member variables in the class package, which dynamically determines the value of the JSP based on other criteria, which in the configuration file ${r} indicates the ability to take values in the value stack.
Conclusion:Ability to save a result with a single attribute;
The results can be determined dynamically by us.
In the struct.xml can use <result>${r}</result> to come inside the value;
"Web Development Learning note" STRUCTS2 result learning Note (ii) dynamic result set