"Web Development Learning note" STRUCTS2 result learning Note (ii) dynamic result set

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.