[JAVAWEB learning notes] online shopping mall practice: Build and complete the user module in the environment, javaweb learning notes

Source: Internet
Author: User

[JAVAWEB learning notes] online shopping mall practice: Build and complete the user module in the environment, javaweb learning notes
Online mall practice

Today's task

  • Complete the functions of the User Module
1.1 online mall practice: 1.1.1 demonstrate online mall functions:

 

 

1.1.2 purpose:

Use the knowledge you have learned to complete the mall practice.

1.1.3 Database Analysis and Design:

 

 

1.1.4 code implementation: 1.1.4.1 General Servlet Compilation:

Traditional methods:

Traditional Method: * a request corresponds to a Servlet. * Can a module correspond to a Servlet? a module corresponds to a Servlet: <a href = "/UserServlet? Method = add "> add </a> <a href ="/UserServlet? Method = update "> modify </a> <a href ="/UserServlet? Method = delete "> delete </a> public class UserServlet extends HttpServlet {public void service (HttpServletRequest req, HttpServletResponse resp) {String method = req. getParameter ("method"); if ("add ". equals (method) {add (req, resp);} else if ("update ". equals (method) {update (req, resp) ;}} public void add (HttpServletRequest req, HttpServletResponse resp) {} public void update (HttpServletRequest req, HttpServletResponse resp) {} improved: public class BaseServlet extends HttpServlet {public void service (HttpServletRequest req, HttpServletResponse resp) {String methodName = req. getParameter ("method"); // reflection: Class clazz = this. getClass (); // refers to the object of the subclass. method method = clazz. getMethod (methodName, HttpServletRequest. class, HttpServletResponse, class); method. invoke (this, req, resp) ;}} public class UserServlet extends BaseServlet {public void add (HttpServletRequest req, incluresp) {} public void update (HttpServletRequest req, HttpServletResponse resp) {}} public class A {public A () {System. out. println (this. getClass () ;}} public class B extends A {Public B () {}} public class Test {Public static void main (String [] args) {B B = new B ();}}

 

1.1.4.2 BaseServlet code implementation:

[Create package structure]

 

[Code implementation] public class BaseServlet extends HttpServlet {@ Override // http: // loacalhost: 8080/store/UserServlet? Method = add protected void service (HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {// garbled req for processing Post requests. setCharacterEncoding ("UTF-8"); // receiving parameter: String methodName = req. getParameter ("method"); // obtain the class bytecode through reflection. class clazz = this. getClass (); // obtain the Method of the specified name of the class being executed try {method Method = clazz. getMethod (methodName, HttpServletRequest. class, HttpServletResponse. class );// Run this method: String path = (String) method. invoke (this, req, resp); if (path! = Null) {req. getRequestDispatcher (path). forward (req, resp) ;}} catch (Exception e) {e. printStackTrace ();}}}

 

1.1.4.3 environment construction:
[Create a WEB project] [Create package structure] [introduce the corresponding jar package] * mysql driver 1 * dbutils 1 * c3p0 Connection Pool 1 * beanutils 2 * JSTL 2 * File Upload 2 * send email 1 [CREATE Database and TABLE] create table 'user' ('uid' varchar (32) not null, 'username' varchar (20) default null, 'Password' varchar (20) default null, 'name' varchar (20) default null, 'email 'varchar (30) default null, 'telphone' varchar (20) default null, 'birthday' varchar (20) default null, 'sex' varchar (10) default null, 'state' int (11) default null, 'code' varchar (64) default null, primary key ('uid') ENGINE = InnoDB default charset = utf8;

 

1.2 Front-End User Module: 1.2.1 register 1.2.1.1 to asynchronously check whether the user name exists

1. JS events trigger a function.

2. Use AJAX to send requests to the server asynchronously.

3. Obtain the returned data for determination.

4. Write the information to the span element behind the text box.

1.2.1.2 complete user registration

1. Enter information on the registration page.

2. Click "register" and submit it to Servlet.

3. Receive and encapsulate data.

4. Call the service layer in Servlet.

5. Page jump.

1.2.1.3 send an activation email

1. Use JavaMail technology-learn more.

* Understand the mail content:

* Term:

* Email: an account on an email server obtains a space on the server through the account.

* Email server: A computer is installed with a mailbox server.

* Email sending and receiving Protocol: The Protocol regulates the data format of both parties.

* Protocol:

* Receiving: POP/POP3 IMAP

* Send: SMTP

* Email sending and receiving process:

* The mailbox client will be configured:

[Configure email server :]

 

 

Installed successfully!

Step 1:

Click Tools → server settings

Step 2:

 

 

Step 3:

Click Account> Create account

[Configure the mailbox client]

* Foxmail: free

* Enter the user name.

* Enter the password:

* Modify the server address localhost.

* Outlook: charged by Microsoft.

1.2.2 Activation

Click the activation link on the email interface:

Submit to Servlet to pass an activation code:

Query users by activation code:

* If the user is queried: Modify the user status.

* If the user is not found, activation fails.

1.2.3 Login

Enter the user name and password on the logon page.

Click Submit: Submit to Servlet.

Receive parameters in Servlet

Call Service Layer

Page Jump

1.2.3.1 remember the user name

Use cookies to remember the User Name:

* Complete by yourself

1.2.3.2 Automatic Logon

Use cookies to remember the user name and password:

Use filter:

* Complete by yourself

1.2.4 exit

* Click the exit link on the homepage:

* Submit to Servlet:

* Destroy session:

 

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.