Let's officially explain the steps:
First, build a JDBC / EDAINFO data source in Tomcat5.x, the database can be Oracle, SQL Server, MySQL. The structure of the table is as follows:
CREATE TABLE EXAMPLE
ID VARCHAR (13) Not NULL,
Name varchar (50) NULL,
Address Varchar (50) NULL
) On [primary]
Where ID is the primary key.
DataSource.xml content is as follows:
XML Version = "1.0" encoding = "GB2312"?>
columns>
rate>
page>
model>
database>
Init-config.xml has been introduced, here is not described in detail here.
Place the above two files into the web-inflicity.
In Web.xml, establish a net.edainfo.filter.setCharacterencodingFilter filter.
Create an ExampleModel.java as follows:
Package Net.edainfo.example;
Import java.util.map;
Import net.edainfo.db.dbmodel;
Import net.edainfo.db.modelexception;
Import net.edainfo.util.format.Encode;
Import net.edainfo.util.format.stringprocessor;
Public Class ExampleModel Extends DBModel {
Public ExampleModel (Map Database) throws modelexception {
Super ("EXAMPLEMODEL", DATABASE);
}
Public void setid (String ID) throws modelexception {set ("id", id);
}
Public string getId () throws modelexception {
Return GetString ("ID");
}
Public void setname (String name) throws modelexception {
Set ("Name", Name);
}
Public string getname () throws modelexception {
Return GetString ("name");
}
Public void setaddress (string address) throws modelexception {
Set ("Address", Address;
}
Public string getaddress () throws modelexception {
Return GetString ("Address");
}
}
Establish an exception class ExampleException.java:
Package Net.edainfo.example;
Import net.edainfo.exception.baseexception;
Public class exampleException extends baseexception {
Static public string createfailed = "exception.createfailed";
Static Public String RetrieveFailed = "Exception.Retrievefailed";
Static public string updatefailed = "exception.Updatefailed";
Static public string deletefailed = "exception.deletefailed";
Static public string [] esampleargs = {"eDAINFO.EXAMPLE"}
}
Built an action, ExampleAction.java:
Package Net.edainfo.example;
Import java.util.arraylist;
Import java.util.map;
Import javax.servlet.http.httpservletRequest;
Import javax.servlet.http.httpservletResponse;
Import net.edainfo.db.dao;
Import net.edainfo.util.Actionbase;
Import net.edainfo.util.edaglobal;
Import net.edainfo.util.FormParameter;
Import net.edainfo.util.page.pagelist;
Import org.apache.struts.Action.actionform;
Import org.apache.struts.Action.actionForward;
Import org.apache.struts.action.actionmapping;
Import org.apache.struts.validator.dynavalidatorform;
/ **
* @Author SLF
*
* Todo to change the template for this generated Type Comment Go to WINDOW - * Preferences - Java - Code Style - Code Templates
* /
Public class exampleAction extends anctionbase {
Public ActionForward Executection (ActionMapping Mapping, Actionform Form,
HTTPSERVLETREQUEST Request, HttpServletResponse Response, Map Params
Throws exception {
DynavalidatorForm Theform = (Dynavalidatorform) Form;
String next = "";
CONN = this.getConnection ();
String Operation = (string) Theform.get ("Operation");
Dao Dao = New Dao (conn, params.get (edaglobals.database_type_key)
"" "
IF (Operation == Null || Operation.equals ("))
Operation = "List";
IF (Operation.equals ("List")) {
EXAMPLEMODEL MODEL = New ExampleModel ((MAP) Params
.get (edaglobals.data_base_key));
String Pagenum = (String) Theform.get ("Pagenum");
IF (Pagenum == Null || Pagenum.equals (")) {
Pagenum = "1";
}
Theform.Set ("Pagenum", Pagenum;
INT PageSize = Model.getPagesize ("Fore");
INT ViewPage = Model.getViewPage ("Fore");
Pagelist Lists = DAO.SELECT (Model, ", New ArrayList ()," ", Integer
.PARSEINT (PAGENUM), PAGESIZE, VIEWPAGE, DAO.DISTINCT_OFF;
Map Parms = FormParameter.SetListPage (Theform, Lists, "EXAMPLE",
REQUEST;
Request.setttribute ("PARMS", PARMS;
Next = "List";
} else if (Operation.equals ("add")) {
EXAMPLEMODEL MODEL = New ExampleModel ((MAP) Params
.get (edaglobals.data_base_key));
Model = (ExampleModel) FormParameter.GetParameter (Model, Theform);
Model.setid (DAO.generateId ());
Dao.create (Model);
Next = "add";} else if (Operation.equals ("addform")) {
Next = "addform";
Theform.Set ("Operation", "Add");
}
Return mapping.findforward (Next);
}
}
Then there is a JSP page, here there are two pages, one is a browsing page, one is a table page;
Browse page, Listexample.jsp:
<% @ Page ContentType = "Text / HTML; Charset = UTF-8"%>
<% @ Taglib Uri = "/ Web-INF / STRUTS-Bean.tld" prefix = "bean"%>
<% @ Taglib URI = "/ Web-INF / STRUTS-HTML.TLD" prefix = "html"%>
<% @ Taglib URI = "/ Web-INF / STRUTS-LOGIC.TLD" prefix = "logic"%>
<%
String linkpage = (string) Request.getaTribute ("linkpage");
%>
hEAD>