Take the user name registration as an example to analyze three kinds of action to obtain data way _java

Source: Internet
Author: User
Tags stub

1. Injection Properties

Direct Injection Properties:

Public String userName;
Public String GetUserName () {return
userName;
}
public void Setusername (String userName) {
this.username = userName;
}
@Override public
String execute () throws Exception {
//TODO auto-generated A stub

user user = new use R ();
User.setusername (UserName)//Here you need to receive and use UserName.
Userdao dao = new Userdao ();
HttpServletResponse response= servletactioncontext.getresponse ();
PrintWriter out = Response.getwriter ();
if (dao.checkexists (user))
{
out.print ("");
}
else
{
out.print ("");
}
return null;
}

2.Domain model This is the usual way

There's no repetition here,

3. Modeldriven

The third method is not commonly used, only need to understand;

The process is divided into 4 steps:
(1) Action Implementation Modeldriven<user> interface

(2) Adding abstract methods

(3) Definition and initialization of a model

User User=new user ();

(4) Generating setters and getter

public class Checkuseraction extends Actionsupport implements modeldriven<user>{
Private User user = new user () ;
Public User GetUser () {return
user;
}
public void SetUser (user user) {
this.user = user
}
@Override public
String execute () throws Exception {
//TODO auto-generated method stub
Userdao dao = new Us Erdao ();
HttpServletResponse response= servletactioncontext.getresponse ();
PrintWriter out = Response.getwriter ();
if (dao.checkexists (user))
{
out.print ("");
}
else
{
out.print ("");
}
return null;
}
@Override public
User Getmodel () {
//TODO auto-generated A stub return
user
}

Note: When using methods 1 and 3, the front-end and JSP code portions need not be changed because they are directly called username properties.

Method 2 needs to change the username in jquery into User.username.

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.