[Web Development Learning Notes] Structs2 Result learning notes (2) dynamic Result set

Source: Internet
Author: User

[Web Development Learning Notes] Structs2 Result learning notes (2) dynamic Result set
Result learning note (2)-do not forget to set the set get method for the saved value of the dynamic Result set.
Part 1: 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" extends="struts-default">        <action name="user" class="com.struts2.user.action.UserAction">    <result>${r}</result>    </action>        </package>    </struts>
// Class 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 2: Configuration Analysis web. xml:
Result:
    <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="/user_error.jsp";return "success";}
The class package contains a member variable that dynamically determines the value of jsp based on other conditions. In the configuration file $ {r}, the value can be set in the value stack.
Conclusion: A property can be used to save a result;
The results can be determined dynamically;
In struct. xml, you can use <result >$ {r} </result> to enter the value;

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.