1. The ArrayList object obtained in UserAction is filled into UserForm, and the jsp page obtains the initial value of UserForm.
Part of the code of UserAction:
Copy the codeThe code is as follows:
private ActionForward executeManageAction(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
UserForm userForm = (UserForm)form;
ArrayList userlist = new ArrayList();
SessionFactory sf= new Configuration().configure().buildSessionFactory();
Session session=();
Transaction tx=();
String sqlQuery="from User";
Query lQuery=(sqlQuery);
userlist=(ArrayList)();
();
();
(userlist);
return ("main_user");
}
Part of the code of UsrForm:
Copy the codeThe code is as follows:
private ArrayList userlist;
public ArrayList getUserlist(){
return userlist;
}
public void setUserlist(ArrayList userlist){
=userlist;
}
JSP page code:
Copy the codeThe code is as follows:
<table style="border-right: darkgreen 1px solid;border-top:darkgreen 1px solid;border-left: darkgreen 1px solid;width:100%;
border-bottom;darkgreen 1px solid;border-collapse:collapse" borderColor="darkgreen" cellSpacing="0" border="1">
<logic:notEmpty name="userForm" property="userlist">
<tr nowrap="nowrap">
<td style="width:80px;height:16px" nowrap><b>Username</b></td>
<td style="width:80px;height:16px" nowrap><b>role</b></td>
<td style="width:84px;height:16px" ><b>Name</b></td>
<td style="width:88px;height:16px" ><b>Tel</b></td>
<td style="width:73px;height:16px" ><b>Email</b></td>
<td style="width:273px;height:16px" ><b>action</b></td>
</tr>
<logic:iterate indexId="index" name="userForm" property="userlist">
<tr>
<td noWrap style="width:80px" ><bean:write name="user" property="username"/></td>
<td noWrap style="width:80px" ><bean:write name="user" property="role"/></td>
<td noWrap style="width:80px" ><bean:write name="user" property="name"/></td>
<td noWrap style="width:80px" ><bean:write name="user" property="tel"/></td>
<td noWrap style="width:80px" ><bean:write name="user" property="email"/></td>
<td nowrap sryle="width:273px" >
<a href="javascript:submitSid(,'<bean:write name="user" property="username"/>')">View</a>
<font >||</font>
<a href="javascript:submitSid(,'<bean:write name="user" property="username"/>')">Update</a>
<font >||</font>
<a href="javascript:if (confirm('Do you delete this user?')){ submitSid(,'<bean:write name="user" property="username"/>')}">Delete</a>
</td></tr>
</logic:iterate>
</logic:notEmpty>
</table>
2. After obtaining the data ArrayList object in UserAction, store the ArrayList object in the request, and the JSP page obtains the ArrayList object.
UserAction part code:
Copy the codeThe code is as follows:
private ActionForward executeManageAction(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
UserForm userForm = (UserForm)form;
ArrayList userlist = new ArrayList();
SessionFactory sf= new Configuration().configure().buildSessionFactory();
Session session=();
Transaction tx=();
String sqlQuery="from User";
Query lQuery=(sqlQuery);
userlist=(ArrayList)();
();
();
("userlist", userlist);
return ("main_user");
}
Part of JSP code:
Copy the codeThe code is as follows:
<table borderColor="darkgreen" cellSpacing="0" border="1">
<tr >
<td ><b>Username</b></td>
<td ><b>Role</b></td>
<td ><b>Name</b></td>
<td ><b>Tel</b></td>
<td ><b>Email</b></td>
<td ><b>Action</b></td>
</tr>
<logic:present name="userlist">
<logic:iterate indexId="index" name="userlist" >
<tr>
<td ><bean:write name="user" property="username"/></td>
<td ><bean:write name="user" property="role"/></td>
<td ><bean:write name="user" property="name"/></td>
<td ><bean:write name="user" property="tel"/></td>
<td ><bean:write name="user" property="email"/></td>
<td >
<a href="javascript:submitSid(,'<bean:write name="user" property="username"/>')">View</a>
<font >||</font>
<a href="javascript:submitSid(,'<bean:write name="user" property="username"/>')">Update</a>
<font >||</font>
<a href="javascript:if (confirm('Do you delete this user?')){ submitSid(,'<bean:write name="user" property="username"/>')}">Delete</a>
</td></tr>
</logic:iterate>
</logic:present>
</table>