Reflection on the course design of Javaweb Online shopping mall

Source: Internet
Author: User

I do not know since when, I fell in love with the blog, the previous study is only to reflect. Wrote a few days course design, code volume of 8,9 thousand or so.

And then the following text is I copied over on the blog, said very detailed

The MVC (model View Controller) design pattern has a better performance than swing in JavaFX. It makes the program interface design and program logic design completely separate, convenient for code readability and later maintainability.

The Java EE architecture adopts the traditional MVC design pattern, which is divided into model, View, controller three layer, which are: models, which define data model and business logic. In order to separate the data access from the business logic, improve the business precision, reduce the coupling between the code, the model layer is subdivided into DAO layer and Business layer, DAO is all called data Access object, the database access code is closed, and Hibernate API is encapsulated in this No longer present on other layers or exposed to other layers; The business layer is the most central and valuable layer of the entire system, encapsulating the business logic of the application, processing the data, focusing on the customer's needs, accessing the raw data or generating new data during the business process, or persisting the data. The DAO layer provides a good way to help the business layer to complete data processing, the business layer itself is focused on customer needs and business rules to understand the adaptation, naturally also includes most of the calculation, in general, DAO does not handle business logic, only for the business layer to provide assistance, to obtain raw data or persisted data and other operations. View is a layer of views, providing a friendly interface for the end user to view the results of the request, or to implement data entry via interactive means such as forms. Controller layer that is, the controller is the model and view of the bridge, will be a good link between the two, through the view to receive user data, the controller will transfer data to Model,model to processing, or model read data, The controller passes the data to View,view to present the data to the user. Shilai, Controller became a happy Messenger between model and view.

System Architecture Mode: MVC architecture pattern (useful to DAO mode)

The project structure of the background management system has the JavaBean class, the DAO interface class, the DAO interface implementation class, the control class, a as shown:

Figure A

The project structure of the front-line mall is JavaBean class, DAO interface class, DAO interface implementation class, control class,

B is shown below:



Figure B



JSP image upload

In general, there are two ways to upload pictures, one is to write the picture file into the database, and the other is to store it in the server file directory. Write to the database picture file needs to be converted into binary stream format, occupy the database space comparison, suitable for a small number of image storage, for example, some small icons in the system, write to the advantages of the database is relatively safe, not easy to be accidentally deleted by the user.


Here are some examples of my online copy:

now whether it is a blog forum or corporate office, can not be separated from the sharing of resources. Through the way of file upload, share with everyone, so as to achieve a wide range of communication and communication between the masses, we can gain more knowledge and experience, but also through the feedback of others to achieve self-improvement and promotion purposes.

I'll introduce you to the following Web This upload feature in the project, how is the file sent from the local to the server? Look at me slowly:

First, we create a new Web Engineering, in the engineering WebRoot Create a new directory under Upload folder so that when we deploy the project to the server, the server also generates a Upload folder, which is used to store uploaded resources.

then, in WebRoot Create a new directory under JSP file, the main implementation of the role is to select the uploaded file, submitted to servlet to do the processing

The detailed code is as follows: a form to pass the file information Post method to the specified servlet

[HTML] View plaincopy

  1. <%@ page language= "java" import= "java.util.*" pageencoding= "Utf-8"%>
  2. <%
  3. String path = Request.getcontextpath ();
  4. String basepath = request.getscheme () + "://" +request.getservername () + ":" +request.getserverport () +path+ "/";
  5. %>
  6. <! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" >
  7. <base href= "<%=basePath%>" >
  8. <title>my JSP ' upload.jsp ' starting page</title>
  9. <meta http-equiv= "Pragma" content= "No-cache" >
  10. <meta http-equiv= "Cache-control" content= "No-cache" >
  11. <meta http-equiv= "Expires" content= "0" >
  12. <meta http-equiv= "keywords" content= "keyword1,keyword2,keyword3" >
  13. <meta http-equiv= "description" content= "This is my page" >
  14. <!--
  15. <link rel= "stylesheet" type= "Text/css" href= "Styles.css" >
  16. -
  17. <body>
  18. <form action= "/upload/upload" method= "post" enctype= "Multipart/form-data" >
  19. Please select the uploaded image or file: <input type= "file" Name= "FileName"/><input type= "submit" value= "Upload"/>
  20. </form>
  21. </body>

as you can see, we submit the data to the project under the Upload/upload .

after that, we're going to write this Servlet--upload.java

[Java] View plaincopy

  1. Package load;
  2. Import Java.io.File;
  3. Import java.io.IOException;
  4. Import Java.io.PrintWriter;
  5. Import java.util.List;
  6. Import Javax.servlet.ServletContext;
  7. Import javax.servlet.ServletException;
  8. Import Javax.servlet.http.HttpServlet;
  9. Import Javax.servlet.http.HttpServletRequest;
  10. Import Javax.servlet.http.HttpServletResponse;
  11. Import Org.apache.commons.fileupload.FileItem;
  12. Import org.apache.commons.fileupload.FileUploadException;
  13. Import Org.apache.commons.fileupload.disk.DiskFileItemFactory;
  14. Import Org.apache.commons.fileupload.servlet.ServletFileUpload;
  15. public class UpLoad extends HttpServlet {
  16. @SuppressWarnings ("Unchecked")
  17. @Override
  18. protected void Service (HttpServletRequest req, HttpServletResponse resp)
  19. Throws Servletexception, IOException {
  20. Req.setcharacterencoding ("Utf-8");
  21. Resp.setcontenttype ("Text/html;charset=utf-8");
  22. Providing configuration information for a parsing class
  23. Diskfileitemfactory factory = new Diskfileitemfactory ();
  24. To create an instance of a resolved class
  25. Servletfileupload SFU = new Servletfileupload (factory);
  26. Start parsing
  27. Sfu.setfilesizemax (1024*400);
  28. The data in each form field is encapsulated on a corresponding Fileitem object
  29. try {
  30. list<fileitem> items = sfu.parserequest (req);
  31. Differentiate form fields
  32. for (int i = 0; i < items.size (); i++) {
  33. Fileitem item = items.get (i);
  34. Isformfield is true to indicate that this is not a File Upload form field
  35. if (!item.isformfield ()) {
  36. ServletContext sctx = Getservletcontext ();
  37. Get the physical path to the file
  38. A folder under upload to get the current online user to find the corresponding folder
  39. String Path = Sctx.getrealpath ("/upload");
  40. SYSTEM.OUT.PRINTLN (path);
  41. Get file name
  42. String fileName = Item.getname ();
  43. System.out.println (FileName);
  44. The method on some platforms (operating system) will return the path + file name
  45. FileName = filename.substring (Filename.lastindexof ("/") +1);
  46. File File = new file (path+ "\ \" +filename);
  47. if (!file.exists ()) {
  48. Item.write (file);
  49. Record the name of the uploaded image in the database
  50. Resp.sendredirect ("/upload/ok.html");
  51. }
  52. }
  53. }
  54. } catch (Exception e) {
  55. E.printstacktrace ();
  56. }
  57. }
  58. }

The design idea of self-study software engineering

Ø definition phase: Feasibility Study preliminary project plan, demand analysis

The purpose of the online mall is to provide an online shopping platform for the vast number of Internet users, making use of the convenience of the Internet to facilitate people's daily life. In order to make it suitable for more users, the system interface design should be as friendly and concise as possible, the realization of the function more humane, convenient for users to buy, so that users can quickly master the use of methods.

This system uses B/s mode, the server side uses the JSP to carry on the dynamic webpage development.

Ø Development phase: Outline design, detailed design, implementation, testing

Online shopping mall can provide a convenient online environment for all kinds of users. Users can register in the system, browse products, place orders, processing orders and other functions; Administrators can maintain updates to the system through management functions such as user management, order management, and commodity management.

Ø operation and Maintenance phase: operation, maintenance, disposal

The online mall is divided into front-end user interface and background management system. So we should test the operation efficiency and stability of the mall. Improve the security and stability of the system.


Activity Chart:

Mall Front Desk Activity Chart



Background Management system activity diagram





Demonstrate:

Online Shop Client



Browse Products


Buy items

Backend Management System:

Upload a picture, then save the picture path to the database







Reflection on the course design of Javaweb Online shopping mall

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.