JSP design mode --- MVC mode 1: Introduction to write ASP and PHP code before, later in order to catch up with the pace of the times. But when you just start writing, you always like to take JSP and ASP Compared to writing the program. Later, I was really stupid. And I wrote the JSP code better to write ASP. It doesn't reflect the power of JSP and Java. Of course, this is what I want to discuss today in JSP. Implement the MVC three-layer mode. Second: What is MVCMVC is an abbreviation of model_view_control. Model_view_control is a typical structure for software design. In this design structure, an application is divided into three parts: Model, View, and Control, each part is responsible for different functions. Model refers to the application's data, and the operation of these data; View refers to the user interface; Control is responsible for the synchronization between user interface and program data, that is, the operation of the two directions: First, in the user interface (view Operation completes the update of program data (Model), and the change is changed to the user interface in time to the user interface. Three: Design thinking When you build a website. 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 Design I usually have two directories when designing Bean: For example, the article system has: com.guessbook.business and com.guessbook.db These two folders (package) Business destinations logic and package data DB Offer Database and Database Connect (Of course I don't use the data pool, it is recommended to use the stored procedure) 5: Design instance I don't know why all write design instances and entry programs like to use a message board, then I use it. Let's have guestbookinfo.java (for encapsulation data) GuestbookFActory.java (Connect DBGuestbook.java) Guestbook.java (used to write abstract classes, interfaces, implement business logic) DBGuestbook.java (all for database) Operation is in this, such as Insert, Update, Select, Delete, and not operate in one method) and dbconnection.java (database connection file) Data table structure Create Table GuestBook (ID INT8 Default NextVal ('seq_guestbook " , / ** primary key ** / title varchar (), / ** Topic ** / body text, / ** content ** / sayid int8, / ** spokesperson ** / toid int8, / ** acceptor * * / saytime datetime default now (), / ** message time ** / newflg shortint default 1 / ** Whether to view ** /); the following is some code, only reference: guestbookinfo.java ======= ================ Import java.util. *; public class guestbook () {private int id; private string title; private body title; private int search; private int standard; private int Date Saytime; Private Short Newflg; Public GuestBook () {} public int getId;} public void setid (int _id) {this.id = _id;} ........ GET / SET method)} GUESTBO Okfactory.java ===================================================== Public Class GuestbookFactory {private static String className = "com.Guestbook.db.DBGuestbook"; public GuestbookFactory () {} public static Guestbook getInstance () {try {return () Class.forName (className) .newInstance ();} catch (Exception e ) {return null;}}} guestbook.java =======
======================= Package com.guestbook.business; import java.util.list; public abstract class guestbook {protected guestbookinfo gi; public guestbook () PUBLIC GUESTBOOKINFO GETGI () {Return Gi;} public void setgi (GuestBookInfo Gi) {this.gi = gi;} public abstract list getGuestbookList (); // The following is your method for database operation} dbguestbook.java = =========================================== .util.ArrayList; import com.Guestbook.business *;. public class DBGuestbook extends Guestbook {String sql; public DBGuestbook () {} public List getGuestbookList () {ResultSet rs = null; List GuestbookList = new ArrayList (); DBConnection conn = new dbconnection (); try {= conn.executeQuery ("SELECT * from Guestbook"); while (rs.next ()) {GuessbookInfo Gi = New GuestbookInfo (); gi.setId (rs.getint ("id" )))); // Implement other methods GuestbookList.Add (GI);}} catch (exception e) {system.err.println ("com.guessbook.db.dbguestbook.getguestbookList ()" "error"); E.PrintStackTrace (); finally {conn.close (); return Gues TBOOKLIST;}}}}} 6: Technical advantages 1: Clear structure 2: Maintenance is convenient 3: The protection code is better. Seven: Conclusion, I just briefly introduced, the specific use you need to accumulate in practical use, if you think he is too rubbish, I said that I am sorry. Writer: Mind