Tried a lot of methods are not successful, finally let me find this method!
First write the code in the background:
Transaction tx = Session.begintransaction (); List List = Session.createsqlquery ("SELECT * from Jike"). List (); Tx.commit (); List List1 = new ArrayList (); Iterator it = List.iterator (); while (It.hasnext ()) {jike user = new Jike ();//This sentence must be placed inside, otherwise the data ob Ject[] Objs = (object[]) it.next (); User.setxuehao (objs[0].tostring ()); User.setname (objs[1].tostring ()); List1.add ( user);} 1.HttpServletRequest request = Servletactioncontext.getrequest (); 2.request.setattribute ("list", List1); return " Success ";
You can also use the STRUTS2 default interceptor without writing 1 and 2, but Java must have both set () and get () methods.
Then write the JSP code that receives the data in the foreground:
<table border= "1" > <s:iterator value = "#request. List" > <tr> <td> <s: Property value= "Xuehao"/> </td> </tr> </s:iterator></table>
The above is a label that uses STRUTS2, or you can use an EL expression:
<td>${name}</td>
Or you can:
<s:iterator> inside plus ID, for example:
<s:iterator value= "#request. List" id= "id" >
<td><s:property value= "#id. Name"/></td>
Use Hibernate session to query the database, and display the table content in the JSP page method