Basic Result usage in Struts2

Source: Internet
Author: User

The Result in Action has a type attribute, which has four common usage methods.
1.

 
  /DemoJsp1.jsp            
 
The address bar does not change when the server jumps.
Method for passing values:
In the address bar, enter http: // localhost: 8080/strutsdemo/hoho/s1? T = 1
JSP page write:
Write in struts. xml:
 
  /DemoJsp1.jsp            
 
You can receive the parameters. Because the server jumps, they share the content in valueStack. 2.
 
  /DemoJsp2.jsp            
 
Client jump, the address bar changes.
Method for passing values:
In the address bar, enter http: // localhost: 8080/strutsdemo/hoho/s2? T = 1

Write in struts. xml:
 
  /DemoJsp2.jsp?r=${t}            
 
Because it is a client jump, ValueStack does not exist, so the t content is saved to the parameters of the Stack Context, and the value can be called through # parameters. r.
The values of the following two methods are the same as those of the preceding method.
3.
              
  S1
               
  /Hoho
  
 
You can jump to action. The server jumps to the action and the address bar does not change.
4.
              
  s2             
  /hoho
 
You can jump to action, client jump, and address bar change. You can configure public results in packaage without writing actions. This is what I wrote in my class.
 
  
   /DemoJsp3.jsp
  
 
package com.struts.app;import com.opensymphony.xwork2.ActionSupport;public class Demo1 extends ActionSupport{private int t;public int getT() {return t;}public void setT(int t) {this.t = t;}@Overridepublic String execute() throws Exception {// TODO Auto-generated method stubif(t==1){return SUCCESS;}else{return "main";}}}

So as long as the input t is not equal to 1, the main is returned. Global-result is called. If you want to call the global-result in another package, you can modify the extends content in the package.
 
  
   
    /DemoJsp3.jsp
   
  
  
   /DemoJsp1.jsp            
  
 
 
  
   /DemoJsp2.jsp            
  
 
Package rr wants to use hoho's global-result to change extends to hoho. In large projects, many people can inherit a public result, so this method is used.

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.