Shopping three major framework ideas and Ajax

Source: Internet
Author: User

I. Registration: JSP

1. Front-end:

<%

Integer regsuccess = (integer) request. getattribute ("regscuess ");
If (regsuccess! = NULL ){
Int I = (INT) regsuccess;
If (I = 1 ){
Out. println ("<SCRIPT> alert ('registered successfully'); </SCRIPT> ");
} Else {
Out. println ("<SCRIPT> alert ('registration failed'); </SCRIPT> ");
}
} // After the verification is completed from the backend, it must be forwarded to the page from the JSP. Otherwise, it is not a request.

%>

JSP collects data. After the user enters the data, click Submit.

 

2. Background:

Action layer // used to jump to a page

Regservlet

Dopost (){

String name = request. getparame ("username ");

User u = new user (); // JavaBean com. Test. Mode

 

U. setusername (name );

Boolean result = service. Reg (U );

// Accept the Boolean variable returned from the service layer

If (result ){

  
// Jump to the page. A prompt is displayed, indicating a success.
Jump to this page,

System. Out. println ("registration successful !! ");
Request. setattribute ("success", 1 );
Requestdispatcher dispatcher = request. getrequestdispatcher ("registerok. jsp ");
Dispatcher. Forward (request, response );
// Response. sendredirect ("OK. jsp ");
} Else {
// Display the cause of the interface failure in the dialog box.
Jump to this page,
System. Out. println ("registration failed !! ");
Request. setattribute ("success", 2 );
Requestdispatcher dispatcher = request. getrequestdispatcher ("register. jsp ");
Dispatcher. Forward (request, response );
// Response. sendredirect ("register. jsp ");
}

}

}

 

Service Layer

Regservice {

Reg (u ){

String username = U. GetUserName ();

Username, password, tel ,...
Validate (); // check
// Query whether the user name has been registered
Boolean result = Dao. isexist (username );
If (result) {// already exists
// Notify the action layer that the user has registered
// Throw new exception (); or return false;
} Else {// enter the information to the database if it does not exist.
Dao. Save (User );
}
Return true;

}

}

 

Dao layer userdao // add, delete, modify, and query

 

 

Ajax: Jump to main. JSP, Main. in JSP, content can be left blank or simply segmented: commodity type, commodity details are included in the onload event, and Ajax is used to obtain all commodity types from the backend servlet. The data format is defined by yourself; parse the string returned by the Background: The string content is displayed on the left in a table;

Servlet: Assemble strings from the service; obtain all product types from Dao;

Additional: JSON array;

Shopping three major framework ideas and Ajax

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.