Action中ArrayList顯示到JSP頁面的具體實(shí)例
一、UserAction中獲取到的ArrayList對象填充到UserForm中,jsp頁面獲取UserForm的初始值。
UserAction的部分代碼:
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");
}
UsrForm的部分代碼:
private ArrayList userlist;
public ArrayList getUserlist(){
return userlist;
}
public void setUserlist(ArrayList userlist){
this.userlist=userlist;
}
JSP頁面代碼:
<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>用戶名</b></td>
<td style="width:80px;height:16px" nowrap><b>角色</b></td>
<td style="width:84px;height:16px" ><b>姓名</b></td>
<td style="width:88px;height:16px" ><b>電話</b></td>
<td style="width:73px;height:16px" ><b>電子郵件</b></td>
<td style="width:273px;height:16px" ><b>動作</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"/>')">查看</a>
<font >||</font>
<a href="javascript:submitSid(document.fview,'<bean:write name="user" property="username"/>')">更新</a>
<font >||</font>
<a href="javascript:if (confirm('刪除此用戶么?')){ submitSid(document.fview,'<bean:write name="user" property="username"/>')}">刪除</a>
</td></tr>
</logic:iterate>
</logic:notEmpty>
</table>
二、UserAction中獲取到數(shù)據(jù)ArrayList對象后,把ArrayList對象存在request中,JSP頁面在獲取到ArrayList對象。
UserAction部分代碼:
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部分代碼:
<table id="id1" borderColor="darkgreen" cellSpacing="0" border="1">
<tr >
<td ><b>用戶名</b></td>
<td ><b>角色</b></td>
<td ><b>姓名</b></td>
<td ><b>電話</b></td>
<td ><b>電子郵件</b></td>
<td ><b>動作</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"/>')">查看</a>
<font >||</font>
<a href="javascript:submitSid(document.fview,'<bean:write name="user" property="username"/>')">更新</a>
<font >||</font>
<a href="javascript:if (confirm('刪除此用戶么?')){ submitSid(document.fview,'<bean:write name="user" property="username"/>')}">刪除</a>
</td></tr>
</logic:iterate>
</logic:present>
</table>
相關(guān)文章
CORBA對象生命周期之實(shí)現(xiàn)和內(nèi)存管理
CORBA對象生命周期之實(shí)現(xiàn)和內(nèi)存管理...2006-10-10Apache FileUpload的兩種上傳方式介紹及應(yīng)用
本文為大家介紹下FileUpload的兩種上傳方式:Traditional API上傳方式/Streaming API上傳方式,感興趣的朋友可以參考下哈,希望可以幫助到你2013-03-03ssh生成隨機(jī)數(shù)字驗(yàn)證碼操作步驟
隨機(jī)數(shù)字驗(yàn)證碼生成方法很多,接下來將介紹下jsp中時如何實(shí)現(xiàn)的,感興趣的朋友可以參考下,希望本文對你有所幫助2013-02-02springMVC使用jsp:include嵌入頁面的兩種方法(推薦)
下面小編就為大家?guī)硪黄猻pringMVC使用jsp:include嵌入頁面的兩種方法(推薦)。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-06-06JSP數(shù)據(jù)庫操數(shù)據(jù)分頁顯示
JSP數(shù)據(jù)庫操數(shù)據(jù)分頁顯示...2006-10-10Spring AOP的實(shí)現(xiàn)原理詳解及實(shí)例
這篇文章主要介紹了Spring AOP的實(shí)現(xiàn)原理詳解及實(shí)例的相關(guān)資料,需要的朋友可以參考下2017-05-05運(yùn)用JSP+ajax實(shí)現(xiàn)分類查詢功能的實(shí)例代碼
本篇文章主要介紹了運(yùn)用JSP+ajax實(shí)現(xiàn)分類查詢功能的實(shí)例代碼,具有一定的參考價值,有興趣的可以了解一下2017-07-07