Hi there,
I just moved to Hibernate 3.0 & Struts 1.2, and wondering how to deal with the resultset.
e.g.
Code:
public Systemuser[] getAllSystemusers() {
/* will hold the systemusers we are going to return later */
List systemusers = new ArrayList();
/* a Hibernate session */
Session session = null;
/* we always need a transaction */
Transaction tx = null;
try {
/* get session of the current thread */
session = HibernateSessionFactory.currentSession();
tx = session.beginTransaction();
Query query = session
.createQuery("from Systemuser order by userid");
for (Iterator iter = query.iterate(); iter.hasNext();) {
systemusers.add((Systemuser) iter.next());
}
tx.commit();
} catch (HibernateException e) {
e.printStackTrace();
// it is recommended to roll back the transaction after an error
// occured
if (tx != null)
try {
tx.rollback();
} catch (HibernateException e1) {
e1.printStackTrace();
}
} finally {
try {
if (session != null)
session.close();
} catch (HibernateException e1) {
e1.printStackTrace();
}
}
return (Systemuser[]) systemusers.toArray(new Systemuser[0]);
}
in Jsp,
Code:
<%@ page language="java" pageEncoding="UTF-8"%> <%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean"%> <%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html"%> <%@ taglib uri="http://jakarta.apache.org/struts/tags-logic" prefix="logic"%> <html> <head> <title>JSP for systemuserListForm form</title> </head> <body> <table border="1"> <tbody>
<%-- set the header --%>
<logic:present name="systemuserListForm" property="systemusers">
<tr>
<td>Userid</td>
<td>Active</td>
<td>Role</td>
<td>Username</td>
<td>Password</td>
<td>Name</td>
<td>Personalid</td>
<td>Regdate</td>
<td>Business</td>
<td>Contact</td>
<td>Phone</td>
<td>Cellphone</td>
<td>Fax</td>
<td>Email</td>
<td>Web</td>
<td>Unit</td>
<td>Address</td>
<td>City</td>
<td>Province</td>
<td>Zip</td>
<td>Country</td>
<td>Logopath</td>
<td>Usersessiontime</td>
<td>Usersessionpage</td>
<td>Userlastvisit</td>
</tr>
<%-- start with an iterate over the collection systemuser --%> <logic:iterate name="systemuserListForm" property="systemusers" id="systemuser"> <tr>
<%-- systemuser information --%>
<td><bean:write name="systemuser" property="userid" /></td>
<%--
<td><html:checkbox disabled="true" name="systemuser" property="active"/></td>
--%>
<td><bean:write name="systemuser" property="role" /></td>
<td><bean:write name="systemuser" property="username" /></td>
<td><bean:write name="systemuser" property="password" /></td>
<td><bean:write name="systemuser" property="name" /></td>
<td><bean:write name="systemuser" property="personalid" /></td>
<td><bean:write name="systemuser" property="regdate" /></td>
<td><html:checkbox disabled="true" name="systemuser" property="business"/></td>
<td><bean:write name="systemuser" property="contact" /></td>
<td><bean:write name="systemuser" property="phone" /></td>
<td><bean:write name="systemuser" property="cellphone" /></td>
<td><bean:write name="systemuser" property="fax" /></td>
<td><bean:write name="systemuser" property="email" /></td>
<td><bean:write name="systemuser" property="web" /></td>
<td><bean:write name="systemuser" property="unit" /></td>
<td><bean:write name="systemuser" property="address" /></td>
<td><bean:write name="systemuser" property="city" /></td>
<td><bean:write name="systemuser" property="province" /></td>
<td><bean:write name="systemuser" property="zip" /></td>
<td><bean:write name="systemuser" property="country" /></td>
<td><bean:write name="systemuser" property="logopath" /></td>
<td><bean:write name="systemuser" property="usersessiontime" /></td>
<td><bean:write name="systemuser" property="usersessionpage" /></td>
<td><bean:write name="systemuser" property="userlastvisit" /></td>
<%-- edit and delete link for each systemuser --%> <td><html:link action="systemuserEdit.do?do=editSystemuser"
paramName="systemuser"
paramProperty="id"
paramId="id">Edit</html:link>
</td>
<td><html:link action="systemuserEdit.do?do=deleteSystemuser"
paramName="systemuser"
paramProperty="userid"
paramId="userid">Delete</html:link>
</td>
</tr>
</logic:iterate>
<%-- end interate --%>
</logic:present>
<%-- if systemusers cannot be found display a text --%> <logic:notPresent name="systemuserListForm" property="systemusers"> <tr> <td colspan="5">No systemuser found.</td> </tr> </logic:notPresent>
</tbody>
</table>
<br>
<%-- add and back to menu button --%>
<html:button property="add"
onclick="location.href='systemuserEdit.do?do=addSystemuser'">Add a new systemuser </html:button> <html:button property="back"
onclick="location.href='default.do'">Back to menu </html:button> </body> </html>
*****************************************
the stake trace
javax.servlet.ServletException: Exception thrown by getter for property role of bean systemuser
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:825)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:758)
org.apache.jsp.jsp.systemuserList_jsp._jspService(systemuserList_jsp.java:313)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.struts.action.RequestProcessor.doForward(RequestProcessor.java:1063)
org.apache.struts.action.RequestProcessor.processForwardConfig(RequestProcessor.java:386)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:229)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1194)
org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)
javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
root cause
javax.servlet.jsp.JspException: Exception thrown by getter for property role of bean systemuser
org.apache.struts.taglib.TagUtils.lookup(TagUtils.java:968)
org.apache.struts.taglib.bean.WriteTag.doStartTag(WriteTag.java:225)
org.apache.jsp.jsp.systemuserList_jsp._jspx_meth_bean_write_1(systemuserList_jsp.java:347)
org.apache.jsp.jsp.systemuserList_jsp._jspService(systemuserList_jsp.java:138)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.struts.action.RequestProcessor.doForward(RequestProcessor.java:1063)
org.apache.struts.action.RequestProcessor.processForwardConfig(RequestProcessor.java:386)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:229)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1194)
org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)
javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
Thanks for any ideas,
Lamborghini[/code]