You can use username registration to analyze three actions to obtain data, and three actions.

Source: Internet
Author: User

You can use username registration to analyze three actions to obtain data, and three actions.

1. Inject attributes


Directly inject attributes:

1 public String userName; 2 3 4 public String getUserName () {5 return userName; 6} 7 8 9 public void setUserName (String userName) {10 this. userName = userName; 11} 12 13 14 @ Override15 public String execute () throws Exception {16 // TODO Auto-generated method stub17 18 User user = new User (); 19 user. setUserName (userName); // here you need to receive and use username. 20 UserDAO dao = new UserDAO (); 21 HttpServletResponse response = ServletActionContext. getResponse (); 22 PrintWriter out = response. getWriter (); 23 if (dao. checkExists (user) 24 {25 out. print ("1"); 26} 27 else28 {29 out. print ("0"); 30} 31 return null; 32}

 


2. Domain Model this is a common method

This is not repeated here,

3. ModelDriven

The third method is not commonly used. You only need to understand it;

The process is divided into four steps:
(1) Implement the ModelDriven <User> interface for action
(2) Add Abstract METHODS
(3) Define and initialize a model
User user = new User ();
(4) generate setter and getter

 1 public class CheckUserAction extends ActionSupport implements ModelDriven<User>{ 2     private User user = new User(); 3     public User getUser() { 4         return user; 5     } 6  7     public void setUser(User user) { 8         this.user = user; 9     }10 11     @Override12     public String execute() throws Exception {13         // TODO Auto-generated method stub14         15         16         UserDAO dao = new UserDAO();17         HttpServletResponse response= ServletActionContext.getResponse();18         PrintWriter out = response.getWriter();19         if(dao.checkExists(user))20         {21             out.print("1");22         }23         else24         {25             out.print("0");26         }27         return null;28     }29 30     @Override31     public User getModel() {32         // TODO Auto-generated method stub33         return user;34     }35     

Note: you do not need to change the front-end and jsp code when using methods 1 and 3, because the userName attribute is directly called.

Method 2: Change username in jquery to user. username.

Related Article

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.