Book Mall
Module
User Module
Classification module
Library Module
Shopping Cart Module
Order Module
Functional analysis
Front desk
User module: Registration/Activation/Login/exit
Category modules: View all Categories
Book module: Query all books/search books by category/inquiry book details (ID)
Shopping Cart Module: Add/empty/delete cart entry/My cart (per user query)
Order module: Generate Order/My order (query by user)/inquiry ORDER by ID/confirm Receipt/
/payment function (jump to bank page only)/Payment callback function
Background
Admin: Login
Classification management: Increase/delete/change/check
Book Management (My): Add (upload image)/delete/change/Search
Order module: Query all orders/By Status Inquiry/issue
Table (Database)
User Module
1 Registration
2 activation
3 Landing
4 exit
Destroy the session/
Code
Web tier
/** * User Presentation Layer */public class Userservlet extends Baseservlet {private UserService userservice = new UserService ();/** * exit function * @param request * @param response * @return * @throws servletexception * @throws ioexception */public String quit (Http ServletRequest request, HttpServletResponse response) throws Servletexception, IOException {request.getsession (). Invalidate (); return "r:/index.jsp";} Public String Login (httpservletrequest request, httpservletresponse response) throws Servletexception, IOException {/* * 1. Encapsulate the form data into the form * 2. Enter the checksum (not written) * 3. Invoke Service Completion activation * > Save error message, form to request, forward to login.jsp * 4. Save user information to session, then redirect to index.jsp */user form = Commonutils.tobean (Request.getparametermap (), user.class); try {User user = Userservice.login (form); Request.getsession (). SetAttribute ("Session_user", user); return "r:/index.jsp";} catch (Userexception e) {request.setattribute ("msg", E.getmessage ()); Request.setattribute ("form", form); return "f:/ Jsps/user/login.jsp ";}} /** * Activation function * @param request* @param response * @return * @throws servletexception * @throws ioexception */public String Active (httpservletrequest req Uest, HttpServletResponse response) throws Servletexception, IOException {/* * 1. Get the parameter Activation code * 2. Call the service method to complete activation * > Save different Information to the request domain, forwarded to msg.jsp * 3. Save the success information to the request domain, forward to msg.jsp */string code = request.getparameter ("code"); try {userservice.active (code); Request.setattribute ("msg", "Congratulations, you have activated successfully!") Please login now! ");} catch (Userexception e) {request.setattribute ("msg", E.getmessage ());} return "f:/jsps/msg.jsp";} /** * Registration Function * @param request * @param response * @return * @throws servletexception * @throws ioexception */public String R Egist (HttpServletRequest request, httpservletresponse response) throws Servletexception, IOException {/* * 1. Encapsulates the form data into the form object * 2. Completion: UID, code * 3. Enter Check * > Save error message, form to request domain, forward to regist.jsp * 4. Call service method to complete registration * > Save error message, form to request domain, forward to regist.jsp * 5. E-mail * 6. Save success message forward to msg.jsp *///encapsulate form data User form = Commonutils.tobean (Request.getparametermap (), user.class);//Complement Form.setuid (Commonutils.uuid ()); Form.setcode (Commonutils.uuid () + commonutils.uuid ());/* * Input checksum * 1. Create a MAP to encapsulate the error message, where key is the form field name and the value is error message */map<string,string> errors = new hashmap<string,string> ();/* * 2. Get the username, password, email to verify */string username = Form.getusername () in the form, if (username = = NULL | | Username.trim (). IsEmpty ()) {Errors.put ("username", "user name cannot be empty!") ");} else if (Username.length () < 3 | | username.length () > Ten) {errors.put ("username", "username length must be between 3~10!") ");} String password = Form.getpassword (); if (password = = NULL | | Password.trim (). IsEmpty ()) {errors.put ("password", "Password cannot be empty!") ");} else if (Password.length () < 3 | | password.length () > Ten) {errors.put ("password", "password length must be between 3~10!") ");} String email = form.getemail (), if (email = = NULL | | Email.trim (). IsEmpty ()) {errors.put ("email", "email cannot be empty!") ");} else if (!email.matches ("\\[email protected]\\w+\\.\\w+")) {errors.put ("email", "email format is wrong!") ");} /* * 3. Determine if there is an error message */if (errors.size () > 0) {//1. Save error message//2. Save form data//3. Forward to Regist.jsprequest.setAttribute ("errors", errors); Request.setattribute ("form", form); return "f:/jsps/user/ Regist.jsp ";} /* * Call the service's Regist () method */try {userservice.regist (form);} catch (Userexception e) {/* * 1. Save exception Information * 2. Save form * 3. Forward to re gist.jsp */request.setattribute ("msg", E.getmessage ()); Request.setattribute ("form", form); return "f:/jsps/user/ Regist.jsp ";} /* * Send email * prepare configuration file! *///Gets the configuration file contents Properties props = new properties ();p rops.load (This.getclass (). getClassLoader (). getResourceAsStream (" Email_template.properties ")); String host = Props.getproperty ("host");//Gets the server host string uname = Props.getproperty ("uname");//Gets the user name string pwd = Props.getproperty ("pwd");//Gets the password string from = Props.getproperty ("from");//Gets the sender string to = Form.getemail ();// Gets the recipient string subject = Props.getproperty ("subject");//Gets the subject string content = Props.getproperty ("content");// Get Message contents content = Messageformat.format (content, Form.getcode ());//Replace {0}session Session = mailutils.createsession (Host, Uname, pwd);//get sessionmail mail = new mail (from, to, subject, content);//Create Mail object try {mailutils.send (session, mail);//email! } catch (Messagingexception e) {}/* * 1. Save Success Information * 2. Forward to msg.jsp */request.setattribute ("msg", "Congratulations, registration succeeded!") Please immediately to the mailbox Activation "); return" f:/jsps/msg.jsp ";}}
Activating service
/** * Activation function * @throws userexception */public void Active (String code) throws Userexception {/* * 1. Use code to query the database to get the user */user User = userdao.findbycode (code); */* 2. If user does not exist, the activation Code error */if (user = null) throw new userexception ("Invalid Activation Code!") ");/* * 3. Verify the status of the user is inactive, if activated, the description is two activations, throws an exception */if (User.isstate ()) throw new Userexception ("You have activated, do not activate again, unless you want to die!") ");/* * 4. Modifies the user's state */userdao.updatestate (User.getuid (), true);}
Classification module
Search All Categories: Main.jsp→categoryservice#findall () →left.jsp
Library Module
Search All Books
Search by Category
Query details (load)
Web day24 Small Project Practice book store, user, module (registration, activation, login, exit), category/library module