Jsp+servlet+javabean+dao

Source: Internet
Author: User

Introduction of each module of the servlet program
1.JSP the part that is used to display and collect data.
2.Servlet for validating data, instantiating JavaBean, invoking DAO Connection database, controlling page jumps
3.DAO for connection to database and database operations such as: query, delete, change, etc.
4.JavaBean for data encapsulation, easy to transfer query results between servlet and JSP pages, etc.
5.servlet Filter It can preprocess the request before a request arrives at the servlet, or it can handle response when leaving the servlet
The 6.servlet listener listens to the various actions of the Web when the associated action is triggered and the event is generated, and the event is processed
The above 1,2,3,4 part together constitute the MVC pattern, JSP for the MVC pattern V,servlet for C,dao and JavaBean together for M.
Second, the mode of operation Flow:
The user first opens a JSP page that collects the data entered by the user (using the Form form implementation), and when the user clicks the Submit button, the JSP page is submitted to the corresponding servlet, at which point the work is turned to the servlet. The servlet processes the data that is submitted to it, and the process is as follows:
1, (optional) to verify the legality of the data, garbled processing, etc.
2. Instantiate DAO, Invoke DAO method (update query operation for database data)
3. Save the data returned by DAO, and save it in an optional location (request,session, etc.)
4. Jump to the page
During the servlet invocation of DAO's method, the DAO process is as follows:
1. Connect to the database (these operations can be placed in the DAO's constructor or written as a separate method)
2. Process the Query method, here are the basic steps. By querying the query and passing the parameters of the database query to get a resultset result set, in order to facilitate the return of the results to the servlet and convenient display, the results are now encapsulated and in Arrarylis or JSON string, The XML string is returned to the servlet in the form of T. In order to encapsulate the data, it is necessary to instantiate a JavaBean, which corresponds to field one by one in the database table, and adds a Get (), set () method for each field.
Serlvet after the data is obtained, the page is then redirected, and the data is saved. We can extract the data from another JSP page and arrange it in a certain format. At this point, a complete query operation is complete.
This operation is relatively simple, but it fully embodies the idea of the MVC pattern.

Jsp+servlet+javabean+dao

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.