How JSP pages traverse a table in a database

Source: Internet
Author: User

I am a beginner, the following is the rookie in the actual use of the record, the great God can skip, of course, also welcome guidance twos
    • Starting with the JSP page, here is the
<s:iterator var= "word" value= "#wordList >//where wordList is associated with the action Context.put (" WordList ", wordList), the list collection in the , list is a database thing, Word is just a variable name    <s:property value= "#word. Details"/>//takes out the details property in the wordlist element with <s:property,  that is, the details field in the database                      </s:iterator>
    • Now come to action

Private String time;
Private stringdetails;


Public String GetTime () {
return time;
}

public void SetTime (String time) {
This.time = time;
}

Public String getdetails () {
return details;
}

public void Setdetails (String details) {
This.details = details;
}

Public String showwordlist () throws exception{
Actioncontext Context=actioncontext.getcontext ();

List<word> wordlist=worddao.getwordlist ();//list collection receives database content from the DAO layer
Context.put ("WordList", wordList);

return "word";
}

    • Then there's the DAO layer.
 Public StaticList<word>Getwordlist () {Session session=hibernatesessionfactory.getsession (); Try{Criteria=session.createcriteria (Word.class); List<Word> word=criteria.list ();//get the table in the database into the list set session.close (); returnword;//returns the list collection}Catch(Exception e) {E.printstacktrace (); }        return NULL; }
    • Then there's the model layer.
 Public classWordImplementsjava.io.serializable{Private Static Final LongSerialversionuid = 1L; PrivateInteger ID; PrivateString time; PrivateString details;  PublicWord () {}//Overloaded Construction Methods     PublicWord (string time, string details) { This. Time =Time ;  This. Details =details; }... The Set,get method for each member is omitted below}

Now it's hbm.xml. Configuration of files related to Hibernate.cfg.xml

//here are the Hbm.xmlclassName= "Com.model.Word" table= "Word" catalog= "se" > <!--Mapping ID field--<id name= "id" type= "java.lang.i Nteger "> <column name=" id "/> <generatorclass= "Identity"/> </id> <!--map Name field--<property name= "Time" type= "java.lang.String "> <column name=" Time "length=" not-NULL= "true"/> </property> <!--map pwd field--<property name= "Details" type= "java.lang.St Ring "> <column name=" Details "length=" not-NULL= "true"/> </property> </class>//here are the Cfg.xmlOrg.hibernate.dialect.MySQLDialect</property> <!--link address--<property name= "Connection.url" >Jdbc:mysql://Localhost:3306/se?useunicode=true&amp;characterencoding=utf-8</property> <!--database user--<property name= "Connection.username" >root</property> <!-- Database user Password--<property name= "Connection.password" >root</property> <!--Connection Driver--&LT;PR Operty name= "Connection.driver_class" >Com.mysql.jdbc.Driver</property> <property name= "Myeclipse.connection.profile" >Com.mysql.jdbc.Driver</property> <property name= "Show_sql" >true</property> <property name= "Format_sql" >true</property> <!--map Files--<mapping resource= "Com/model/word.hbm.xml"/></session-factory>&lt ;/hibernate-configuration>
    • Next is the Struts.xml configuration.
class= "Com.action.WordAction" >            <result name= "word" >/user/word.jsp</result></ Action>

How JSP pages traverse a table in a database

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.