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