The ArrayList object obtained in Useraction is populated into UserForm, and the JSP page gets the initial value of UserForm.
Part of Useraction code:
Copy Code code 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=sf.opensession ();
Transaction tx=session.begintransaction ();
String sqlquery= "from User";
Query lquery=session.createquery (sqlquery);
Userlist= (ArrayList) lquery.list ();
Tx.commit ();
Session.close ();
Userform.setuserlist (userlist);
Return Mapping.findforward ("Main_user");
}
Part of Usrform code:
Copy Code code as follows:
Private ArrayList userlist;
Public ArrayList getuserlist () {
return userlist;
}
public void Setuserlist (ArrayList userlist) {
This.userlist=userlist;
}
JSP page code:
Copy Code code as follows:
<table id= "Id1" 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" id= "user" 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 (Document.fview, ' <bean:write name=" user "property=" username "/> ')" > View < /a>
<font >| | </font>
<a href= "Javascript:submitsid (Document.fview, ' <bean:write name=" user "property=" username "/>") "> Update < /a>
<font >| | </font>
<a href= "javascript:if confirm (' Delete this user? ')} {submitsid (Document.fview, ' <bean:write name= "user" property= "username"/> ')} "> Delete </a>
</td></tr>
</logic:iterate>
</logic:notEmpty>
</table>
after acquiring the data ArrayList object in Useraction, the ArrayList object exists in request, and the JSP page obtains the ArrayList object.
Useraction part of the code:
Copy Code code 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=sf.opensession ();
Transaction tx=session.begintransaction ();
String sqlquery= "from User";
Query lquery=session.createquery (sqlquery);
Userlist= (ArrayList) lquery.list ();
Tx.commit ();
Session.close ();
Request.setattribute ("UserList", userlist);
Return Mapping.findforward ("Main_user");
}
JSP Part code:
Copy Code code as follows:
<table id= "Id1" bordercolor= "Darkgreen" cellspacing= "0" border= "1" >
<tr >
<TD ><b> User Name </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" id= "user" 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 (Document.fview, ' <bean:write name=" user "property=" username "/> ')" > View < /a>
<font >| | </font>
<a href= "Javascript:submitsid (Document.fview, ' <bean:write name=" user "property=" username "/>") "> Update < /a>
<font >| | </font>
<a href= "javascript:if confirm (' Delete this user? ')} {submitsid (Document.fview, ' <bean:write name= "user" property= "username"/> ')} "> Delete </a>
</td></tr>
</logic:iterate>
</logic:present>
</table>