Javaweb Project Exercises (10)

Source: Internet
Author: User

Brief introduction

These two projects are pre-learned knowledge synthesis, combined with MVC thought to complete the small project. This is just a pseudo-code-like idea. No code is provided, because there is a lot of code and there is no real idea. The experience of the two projects is that the initial study did not knock out the first. You can only master it with constant repetition.

User Registration case
1. Setting up the Environment 1.1 Development Package DOM4J Development Package Beanutils Kit/LOGGINGJSTL Development Kit 1.2 Create an Organizational package Com.itheima.domaincom.itheima.daocom.itheima.dao.implcom.itheima.servicecom.itheima.service.implcom.itheima.web.cont Rollercom.itheima.utilsjunit.testweb-inf/jsp put all sites jsp1.3 create a representative database XML File Development Prelude Guide Package beanutils/loggingdom4j/jaxenjstl/ Standard1. Users.xml as a database store file 2. Define the user entity class private string Id;private string Username;private string password;private string email; Private Date birthday;private String nickname;3. Operation entity Class 4. Define the interface userdao--> define the implementation class Userdaoimpl (determine if the user exists)--Define the tool class action XML file DOM4JUTILS5. Define business logic, provide services to the previous tier UserService interface--->userserviceimpl interface: Home index.jsp (determine if there is a user login c:if tag) login page login.jsp (hide domain settings operation information, Purpose for the Address bar does not display request parameters) registration page register.jsp (Registration form Value-<span area display error message >)/hidden field settings Iduserformbean class private String Id;private String Username;private string Password;private string repass;private string Email;private string birthday;private String nickname;private map<string,string> errormsg = new hashmap<string,string> (); Validate () Method ControllerservletClass 1. Solve the form garbled problem 2. Gets the action type parameter 2.1 user logon action 2.1.1 Gets the value of the user name and password 2.1.2 calls the business logic (determines whether the login succeeds) 2.1.3 If the login succeeds, the user information is stored in the session, redirect the home page otherwise fails, prompts the message, and jumps to login 2.2 Register Operation 2.2.1 The value of the registration page input populate the Userformbean object with a Webutils tool class, define the fill Fillbean method 2.2.2 Verify that the Business entity class (Formbean Class) is valid (validate), No explanation for null Formbean setting in the request domain---> forward to register.jsp current page method End 2.2.3ConvertUtils---(datelocaleconverter,date.class) Copy the Formbean data to user (before copying to register date, otherwise inconsistent type) Registration date Mode 2. Convertutils The Register method overrides converter Method 1. Determines whether it is empty 2. The strongly-converted string type determines whether it is "" 3. Create a date format Class 4. Then parse into a date format return 2.2.4 business logic implementation registered user, prompt registration success, 1 seconds after jumping to the login page otherwise the user name already exists, add the error information to the collection, set Formbean in the request domain, forward to the current registration page 2.3 Logoff Action 2.3.1 Redirect user information to the Home page summary: involves the request domain use forwarding involves session domain using redirect has jump demand set Refresh header information page design 1. Home index.jsp Use the c:if tag in the tag library to determine if user is empty, if not empty, display the Welcome prompt if blank displays sign-in and sign-up prompt 2. Login page login.jsp, login form submitted to controller, hidden domain setting submission Method 3. Register page register.jsp, date control usage 3.1 birthday-calendar.js Calendar control using <script type= "text /javascript "src=" ${pagecontext.request.contextpath}/js/birthday-calendar.js "></script><input readonly= "ReadOnly" onclick= "New Calendar (). Show (this);" type= "text" name="Birthday"/>3.2 the span area and the input box using an EL expression to get the value in the session 

Shopping Cart Code Ideas
Pre-DB/DOMAIN/DAO/SERVICE/CONTROLLER/UI2 preparation. Development of Dao3. Development of Service4. Development of Web1. The DB class simulates the book Database 1.1 DB Class Map--->linkedhashmapmap.put ("1", New book ("1", "Javaweb development", "Lao Zhang", 38, "a Good Books")), Map.put ("2", new Book ("2", "JDBC Development", "Lao Li", 18, "a good one"), Map.put ("3", New Books ("3", "Ajax Development", "Lao Bi", 328, "a Good Book")), Map.put ("4", New Books ("4", "JBPM Development", "Old Fang", 58, "a Good book"), Map.put ("5", New Books ("5", "Struts development", "Lao Zhang", 28, "a Good Book")), Map.put ("6", New Books ("6", " Spring development, "Lao Li", 98, "a Good book");---getAll () Method--Get all Books 1.2----Book class-----private string Id;private string name;private string Author;private int price;private string description;2. Defining a data Access Layer class Bookdaoimpl, in fact, is two methods 2.1 get all the books returned map2.2 according to the ID returned by this book 3. Shopping Cart class Cart/private map<string,cartitem> Map = new Linkedhashmap ();(store the book's ID and shopping items) private double price; Total price of all items in cart getprice ()----totalprice---> Traverse all purchases in the Map collection, and each purchase item is added together to get the total price public void add to get the shopping item by the book ID---map.get (Book.getid ()); If a shopping item is empty create a shopping item--add book to shopping item (Setbook)---> Quantity quantity to 1 otherwise directly modify the quantity setquantity (item.getquantity  () +1); 4. Shopping Item Class Cartitemprivate book Book;private int quantity; Note When you set the quantity, you want to modify the price at the same time = GetPrice () *quantityprivate double price;5. Business logic handles the Businessserviceimpl Class 1. Get all books/Find books by Book ID 2. Delete the shopping item--id,card3 in the shopping cart. Empty the shopping cart cart4. Modify the quantity in your shopping cart--first get a shopping item based on the specified ID, and then modify the quantity id,cart,quantity6 in the shopping item.  The UI page forwarding class Listcartuiservlet forwards to the shopping cart page getrequestdispatcher ("/web-inf/jsp/listcart.jsp"). Forward (); 7. The Web control layer writes a master controller ControllerServlet1). First, get the action type requested by the client to save 2 with op). Get the shopping cart (created at the time of purchase) by the Session Field 3). Gets the ID of the requested book, which facilitates the operation of this book if ("Showbooks". Equals (OP)) {showbooks (request,response); Request.getrequestdispatcher ("/ Web-inf/jsp/listbook.jsp "). Forward (request, response); return;} else if ("buy". Equals (OP)) {Buy (request,response, cart,id);} else if ("Change". Equals (OP)) {Change (Request,response, Cart,id);} else if ("delete". Equals (OP)) {delete (request,response,cart,id);} else if ("clear". Equals (OP)) {Clear (Request, Response,cart);} 7.1 Request to show all books Showbooks get a collection of all books, set the collection to the request domain and redirect to listbook.jsp on page 7.2 requesting purchase operation type BUY2). The business Logic layer finds book 3 through the requested ID implementation). Get Cart 4 via session field). If the shopping cart is empty, create a shopping cart and set the cart to the Session field 5). Add a book to your shopping cart7.3 Request Delete Type 3). The business logic implementation removes the shopping item by ID 7.4 request emptying type 2). Business logic realization through shopping cart empty shopping cart All Books 7.5 Request modification Type 1). Gets the number of modifications 3). Business logic implementation through shopping cart, ID, modify quantityfinally , don't forget redirect listcart.jspPage Design 1. Index.jsp browses the book-to-hyperlink to the-->controllerservlet class with the request parameter showBooks2. listbook.jsp Book page-->* header *: Title/author/price/description/Action Traverse Map Collection Show All books: (Action hyperlink to purchase page will send ID to Controllerservlet class, request parameter is Buy) 3. Shopping Cart Page listcart.jsp3.1 determine whether the shopping cart has books, no books on the direct output without buying any goods 3.2. Otherwise, the shopping cart form details are displayed * Header *: Title/author/unit price/Quantity/Subtotal/operation foreach traverse the book cart.map1 in the shopping cart). * (javascript:void (0))--click event Deletitem (the ID of the Entry.key book passes through) By window.confirm to determine whether to delete, if the deletion is window.location.href=controllerservlet?id= ' "+id+" ", the request parameter type is DELETE2). (Quantity quantity can be entered manually---> Change event changequantity (this, book ID, number of books) ****1> Defines the value of the number of variables received to determine whether the number of inputs is less than 0 or quantity!= parseint (quantity), if prompted to set up a message, the old value assigned to value, directly return to 2>.window.confirm otherwise prompted to confirm the number of changes + Quantitywindow.location.href confirm controllerservlet?id= "+id+" &quantity= "+quantity; the request parameter type is CHANGE3). * * Tail * *: Total Price---->cart.price (empty shopping cart hyperlink javascript:void (0))---> Click event Clearcart (); Window.confirm determine whether to delete, if delete window.location.href= "Controllerservlet", request parameter type is clear

Javaweb Project Exercises (10)

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.