MVC architecture pattern and the use of JavaBean paging

Source: Internet
Author: User

It is well known that MVC is not a design pattern, a larger pattern than a design pattern, called the design pattern is unreasonable, the MVC pattern should be called the architectural pattern, MVC uses many small patterns, for example, the strategy pattern, the combination pattern, the aggregation pattern, can use the pattern to have more than 10 kinds of, but the design pattern also has 27 kinds, MVC is important, now the popular struts framework is similar to the implementation, suggesting that you have time to study the struts, now many companies are starting to use this framework for large-scale enterprise system development, struts is an open source project Apache, All information can be obtained from the Apache website. Of course, there are some of the domestic translation of struts article, but most incomplete, the introduction is the primary knowledge, if you want to further study can buy a book of struts.

MVC is the Model-view-console, M is Javabean,v Jsp,c is the Java Servlet.

The first step is to write the Hashtable class and write all classes and JSP file paths here

The second step is to write the most abstract interface interface, giving a method such as

public void execute (httpservlet servlet,httpservletrequest request,httpservletresponse response);

All servlet classes that interact with the client must implement the Execute method of this interface in order to execute in the factory.

The third step to write the console, in fact, I think that is the factory model of a higher factory model.

To perform the corresponding class according to the action

Web. XML file As long as the configuration of an action on it, you should be familiar with it, for example

<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app
   PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
   "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<servlet>
<servlet-name>servlet_name</servlet-name>
<servlet-class>servlet_class_path</servlet_class>
</servlet>
<servlet-mapping>
<servlet-name>servlet_name</servlet-name>
<url-pattern>映射名</url-pattern>
</servlet-mapping>
</web-app>

It's a lot easier. Not every action in each class is added to the XML file. In addition, it is more convenient to modify the function later.

The use of JavaBean paging is actually very simple, but to write a structure of the words at least need 3 classes, a bean class, a processing page number and other data, one get the client value, below I give an example, if there is anything do not understand please follow.

A simple Bean class

package geezer_model.geezer_user;


public class Listuser_bean {


String name;


String Pass;


public void SetName (String name) {


This.name=name;


}


public void SetPass (String pass) {


This.pass=pass;


}


public String GetName () {


return this.name;


}


public String Getpass () {


return this.pass;


}


}





simple processing of paging data class


package geezer_model.geezer_user;


import javax.sql.*;


import java.sql.*;


import geezer_controller.*;


import geezer_database.getconnection;


public class Listuser_page {


public Listuser_page () {





  }


Connection Conn=null;


Statement Simt=null;


ResultSet Rs=null;


int intpage=1;


int intpagecount=10;


int pagecount=20;


int page_listcount=1;


String SQL;


Public listuser_bean[] GetPage (int intpage,int intpagecount,string sql) {


This.intpage=intpage;


This.intpagecount=intpagecount;


This.sql=sql;


listuser_bean[] Tmie=null;


try{


conn=getconnection.getnewconnection ();


simt=conn.createstatement ();


rs=simt.executequery (This.sql);


if (Rs.next ()) {


Rs.last ();


Pagecount=rs.getrow ();


page_listcount= (pagecount+intpagecount-1)/intpagecount;


if (intpage&gt;page_listcount) {


Intpage=page_listcount;


}


int pagewo= (intpage-1) *intpagecount+1;


if (pagewo&gt;0) {


Rs.absolute (Pagewo);


}


Tmie=new Listuser_bean[intpagecount];


int i=0;


do{tmie=new Listuser_bean ();     Tmie.setpass (rs.getstring ("password")); Tmie.setname (rs.getstring ("username"));


} while (Rs.next () &amp;&amp; ++i &lt; Intpagecount);


}


}catch (Exception e) {


E.printstacktrace ();


}


Setlistcount (Page_listcount);


SetCount (PageCount);


return Tmie;


}


public void SetCount (int a) {


This.pagecount=a;


}


public void Setlistcount (int b) {


this.page_listcount=b;


}


public int GetCount () {


return PageCount;


}


public int GetListCount () {


return page_listcount;


}


}

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.