"Javaweb Study notes" online Shop real Combat: Environment Building and completion of user modules

Source: Internet
Author: User

Online Mall Combat

Today's mission

    • Complete the functionality of the user module
1.1 Online shopping mall's actual combat: 1.1.1 Demo online store function:

1.1.2 Production Purpose:

Flexible use of the knowledge learned to complete the mall actual combat.

1.1.3 Database analysis and Design:

1.1.4 Code implementation: 1.1.4.1 Common servlet writing:

The traditional way:

the traditional way:*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 classUserservletextendshttpservlet{ Public voidService (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 voidAdd (httpservletrequest Req,httpservletresponse resp) {} Public voidUpdate (HttpServletRequest Req,httpservletresponse resp) {}} after improvement: Public classBaseservletextendshttpservlet{ Public voidService (HttpServletRequest Req,httpservletresponse resp) {String methodName=Req.getparameter ("method"); //Reflection:Class Clazz = This. GetClass ();//the object that refers to the child class.Method method = Clazz.getmethod (MethodName, HttpServletRequest.class, HttpServletResponse,class); Method.invoke ( This, REQ,RESP); }} Public classUserservletextendsbaseservlet{ Public voidAdd (httpservletrequest Req,httpservletresponse resp) {} Public voidUpdate (HttpServletRequest Req,httpservletresponse resp) {}} Public classa{ PublicA () {System.out.println ( This. GetClass ()); }} Public classBextendsa{Public B () {}} Public classtest{ PublicStatic voidMain (string[] args) {b b=NewB (); }}

1.1.4.2 Baseservlet's Code implementation:

"Create Package Structure"

"Code Implementation" Public classBaseservletextendshttpservlet{@Override// Http://loacalhost: 8080/store/userservlet?method=add    protected voidService (HttpServletRequest req, HttpServletResponse resp)throwsservletexception, IOException {//handling of garbled post requestsreq.setcharacterencoding ("UTF-8"); //Receive parameters:String MethodName= Req.getparameter ("method")); //reflection Gets the byte code of the class.Class Clazz= This. GetClass (); //method to obtain the specified name of the class being executed        Try{Method Method= Clazz.getmethod (MethodName, HttpServletRequest.class, HttpServletResponse.class); //let this method execute:String Path= (String) Method.invoke ( This, REQ,RESP); if(Path! =NULL) {req.getrequestdispatcher (path). Forward (req, resp); }        } Catch(Exception e) {e.printstacktrace (); }    } }

Construction of 1.1.4.3 Environment:
"Create a Web Project" "Create Package Structure" "introduce the appropriate jar package"* MySQL Driver 1 * dbutils 1 * c3p0 Connection Pool 1 * Beanutils 2 * JSTL 2 * File upload 2 * Send mail 1"CREATE DATABASE and table" Creating 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, ' telephone ' varchar (20) DEFAULT NULL, ' birthday ' varchar (20) DEFAULT NULL, ' sex ' varchar (10) DEFAULT NULL, ' state 'int(11) DEFAULT NULL, ' Code ' varchar (64DEFAULT NULL, PRIMARY KEY (' uid ')) ENGINE=innodb DEFAULT Charset=utf8;

1.2 Front desk User module: 1.2.1 Registration 1.2.1.1 The existence of an asynchronous check user name

The event of 1.JS triggers a function.

2. Asynchronously sends a request to the server using AJAX.

3. Obtain the data returned to judge.

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

1.2.1.2 Complete User Registration

1. Enter the information in the registration page.

2. Click Register to submit to servlet.

3. Receive data and encapsulate data.

4. Invoke the business layer in the servlet.

5. Page jumps.

1.2.1.3 Sending an activation message

1. Using the JavaMail technology-understand.

* Learn about email content:

Term

* E-mail: An account on a mailbox server to get a space on the server.

* Mailbox server: A server that installs a mailbox on a single computer.

* e-mail protocol: The format of data on both sides of the protocol specification.

Agreement

* Receive: POP/POP3 IMAP

* Send: SMTP

* Mail sending and receiving process:

* Clients that will configure the mailbox:

"Configure Mailbox server:"

Installation is successful!

The first step:

Click tools → server settings

Step Two:

Step Three:

Click account → new account

"Configure clients for a mailbox"

* Foxmail: free of charge

* Enter user name

* Enter Password:

* Modify the server's address localhost.

* Outlook: Microsoft is charged.

1.2.2 Activation

Click on the activation link in the email interface:

Commit to the servlet to pass an activation code:

To query the user according to the activation code:

* If the user is queried: Modifies the user's state.

* If no query to the user: Activation failed.

1.2.3 Login

Enter your user name and password on the login page

Click Submit: Submit to servlet.

Receiving parameters in the servlet

Calling the business layer

Page Jump

1.2.3.1 Remember user name

Use cookies to remember your user name:

* Do it Yourself

1.2.3.2 Automatic Login

Use cookies to remember your user name and password:

Using filters:

* Do it Yourself

1.2.4 Exit

* Click on the exit link on the home page:

* Submit to Servlet:

* Destroy session:

"Javaweb Study notes" online Shop real Combat: Environment Building and completion of user modules

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.