Struts2 _ receiving Parameters

Source: Internet
Author: User

1.1
Directly create the received data type

1 public class helloaction extends actionsupport {2 3 private string name; 4 private int age; 5 6 Public String add () {7 system. out. println ("name =" + name); 8 system. out. println ("age =" + age); 9 return success; 10} 11 12 Public String getname () {13 return name; 14} 15 16 public void setname (string name) {// The server automatically calls 17 this. name = Name; 18} 19 20 public int getage () {21 return age; 22} 23 24 public void setage (INT age) {25 this. age = age; 26} 27}

 


In the URL: http: // localhost: 8080/struts2_0100_introduction/helloaction_add? Name = A & age = 123
1.2
Create a user class and place the received Parameters

 1             public class User { 2                 private String name; 3                 private int age; 4                 public String getName() { 5                     return name; 6                 } 7                 public void setName(String name) { 8                     this.name = name; 9                 }10                 public int getAge() {11                     return age;12                 }13                 public void setAge(int age) {14                     this.age = age;15                 }16             }

 


New User class is not required

 1             public class UserAction extends ActionSupport{ 2                 private User user; 3                  4                 public String add(){ 5                     System.out.println("User is run."); 6                     System.out.println("name="+ user.getName()); 7                     System.out.println("age="+user.getAge()); 8                     return SUCCESS; 9                 }10                 public User getUser() {11                     return user;12                 }13                 public void setUser(User user) {14                     System.out.println("setUser run");15                     this.user = user;16                 }17             }

 


In the URL: http: // localhost: 8080/struts2_0100_introduction/useraction_add? User. Name = A & User. Age = 123
1.3
Not Required
Create a user class and place the received Parameters
Public class user {
Added implements modeldriven <user>
New User

1 public class modeluseraction extends actionsupport implements modeldriven <user> {2 private user = new user (); 3 4 Public String add () {5 system. out. println ("modeluser is run. "); 6 system. out. println ("name =" + User. getname (); 7 system. out. println ("age =" + User. getage (); 8 return success; 9} 10 11 @ override12 public user GetModel () {13 // todo automatically generated method stub 14 return user; 15} 16}

 


URL: http: // localhost: 8080/struts2_0100_introduction/modeluser_add? Name = A & age = 123

Struts2 _ receiving Parameters

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.