Struts2 dynamic result set

Source: Internet
Author: User

Struts2 dynamic result set

1. index. jsp

Do not forget to set the set get method for the saved values of dynamic results.
  1. Return success
  2. Error returned

2. struts. xml
<struts>  <constant name="struts.devMode" value="true">  <package extends="struts-default" name="user" namespace="/user">                <action class="com.wxh.action.UserAction" name="user">            <result>${r}</result>        </action>        </package></constant></struts>

3. UserAction. java
Package com. wxh. action; import com. opensymphony. xwork2.ActionSupport; public class UserAction extends ActionSupport {/***/private static final long serialVersionUID = 1L; 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;} // dynamically determine the value of r public String execute () throws Exception {if (type = 1) r = "/userSuccess. jsp "; else if (type = 2) r ="/userError. jsp "; return" success ";}}
4. userError. jsp
User error! 

5. userSuccess. jsp
User Success! 

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.