Hands-on to do a JSP Getting Started program (i): The basic introduction of the program (JSP)

Source: Internet
Author: User
nonsense

Agreed not to learn JSP, the results today or learn. Mainly for the back of the Java backstage learning. For better mastery of knowledge, let's write a simple JSP entry program. This is just a simple getting started applet, so there's not a lot of powerful functionality. Getting started, getting started. Yes, as a starter program, so there will be more knowledge points introduced, so it will be longer.

  The front-end source code can click here to download, the project depends on the jar package can click here to download, the project complete code can click here to download. It is recommended to download the complete source code before continuing to read.
  you can also click here to download another more complete version of the front end code for this page. If you are interested in Nodejs, you can click here to see a NODEJS implementation, including the shopping cart features of the project source.
  You can click here to see this little JSP introductory tutorial on Gitbook. Final effect & business logic Home


Home Structure Chart

From the structure of the home page, it is easy to know, we just need to grasp the data of the database down, and render up on it. So here we mainly learn the most basic JSP knowledge points and the interaction with the MySQL database. In addition, the add to cart operation here is implemented using AJAX, while the status information of the operation is returned. Product Detail Page


Product Detail Page Structure chart

The basic page structure and the homepage almost, but the main part and the first page is not the same. In the Product detail page, we mainly focus on the implementation of browsing records. The items that the user browses to are recorded through cookies and display the latest 4 records. So the important thing here is the use of cookies. In addition, here will also mention the session of the relevant knowledge points. Login interface and Registration interface

Starting with login registration, we will use the servlet for development. You need to know what the servlet base is, click here.

Registration interface

Login interface

Shopping Cart Show


Shopping Cart Interface
The realization of the shopping cart in fact, as long as the user UID and book ISBN connected to the equivalent of the user to buy the book, so the following database design, readers can be a little shopping cart database design. In addition, the deletion here is also using AJAX.

Project usage Model

There are two development models for JSP development, one is the two-layer model of Jsp+javabean, the other is the Servlet+jsp+javabean three-layer model. JavaBean in the following "Commodity entity class Design" section will have a brief introduction. two-layer model of Jsp+javabean


Model 1:jsp+javabean

In this model, JSP is responsible for processing business logic and displaying data, while JavaBean is responsible for encapsulation of business data. corresponding to the MVC model, then the JSP contains the controller and view two parts, JavaBean for the model section. The disadvantage of this model is that the control logic and performance logic are all processed in JSP, so when dealing with very complicated business process, the Java code embedded in JSP page is very much, which brings great difficulty to development and maintenance. This model is something I don't like very much. As an introduction to JSP, the first half of this tutorial will be developed using this two-tier model, the second half of which will be developed using a three-tier model, enabling both models to be learned. the three-layer model of Servlet+jsp+javabean

The model is based on the MVC architecture pattern, where the servlet acts as a controller, handles requests and controls the business process, and the JSP acts as the role of the view, responsible for outputting the response results, JavaBean as the role of the model, and responsible for the specific business logic and business data.

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.