JSP design mode [reproduced]

zhaozj2021-02-16  106

jsp design patterns Date: 2002-04-14 Author: bingo ------------------------------------ ----- Reserved: http://www.cnjsp.org/view.jsp? Column = 2 & id = 603 JSP Design Mode 1: Introduce Member Beginner JSP, I always like to compare him and ASP, PHP, also It is accustomed to using the ASP development model to write JSP, and then discovered that this is really stupid. In fact, JSP has already used MVC mode. Below I briefly say that JSP design uses MVC to design. 2: MVC introduction MVC is actually an abbreviation, view, controlled abbreviation, that is, when using JSP, there is a corresponding file to achieve the corresponding operation. Usually JSP is only responsible for View is only responsible for displaying pages. BEAN (EJB) is implemented in business logic. The discussed below is achieved without using EJB. If you use EJB, EJB is responsible for M.c usually by servlet. Or use Struts. Struts introduction You go to http://jakarta.apache.org/struts to see. I will introduce in later articles. Three: Design Thoughts When you build an Application. You must consider the problem of interface, and interface modification is very common. If you implement all your operations in JSP, you have trouble in the modification interface. The art does not understand JSP, you must go to revise countless files, don't be too big, and at this time, you will be very tight, you can reduce your troubles. JSP is only responsible for displaying the page at the design, that is, the JSP calls the data passed by the bean (Struts, servlet) and then the bean (struts, servlet) is responsible for collecting the data required by JSP, transmitting the ARRAYLIST (ArtTIBUTE) to JSP. If you need to submit a form, it is generally directly submitted to the struts, servlet, and then returns the processing information later. And the corresponding business logic is implemented by bean. Four: Bean's design When I use, beans usually have three types, separately, Entry, Database directory. The bean under Manager as the commercial logic entry is packaged data, in fact, every database table corresponds to a bean. All JSP is all class. The bean under Database is the operational database, performs such as Insert, Update, Delete, Load (query a record), BatchLoad (Query multiple records). The relationship between them is entry responsible for packaging data, as a calling parameters of Database, returns the result. Manager calls the result of the Database processing. Manager and JSP communications. The results obtained from JSP come from Manager, JSP needs to do operation calling Manager, even an insert has such a method in Database but in Manager, you still need to package it once. The purpose of this is to make the structure as simple as possible. Database is only responsible for operating the database.

Manager is only logically (take the appropriate data) to handle the corresponding logic, and the entry only takes the data package taken by Database, or encapsulates the parameter to the page, as a parameter passed to the corresponding bean. 5: Design instance I discuss the message board as an example: entry / guestbook.java (Message object) Database / GuestbookMap.java (Update, Remove, Modify Message Board) Manager / GuestbookManager.java (Processing All Transactions) Data Table Structure (PostgreSQL) Create Sequence Seq_Guestbook Increment 1; / ** Serial number generator ** / create table guestbook (ID INT8 Default NextVal ('seq_guestbook'), / ** Primon ** / Title Varchar (64), / ** Topic ** / Body text, / ** content ** / sayid int8, / ** spokesman ** / toid int8, / ** acceptor ** / saytime datetime default now (), / ** message time ** / newflg Smallint Default DEFAULT 1 / ** Whether you view ** /); guestbook.java ============================================================================================================================================================================================================================================ {Private INT ID; Private Body Title; Private Int SayID; Private Date Saytime; Private Short Newflg; Public Guestbook () {} PUBL IC Int getId () {returnid;} public void setid (int _id) {this.id = _id;} ........ (all GET / SET method)} guestbookmap.java === ===================================00

转载请注明原文地址:https://www.9cbs.com/read-14422.html

New Post(0)