国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 編程 > JSP > 正文

Action中ArrayList顯示到JSP頁(yè)面的具體實(shí)例

2024-09-05 00:21:53
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友
UserAciton中通過(guò)hibernate查詢到的數(shù)據(jù)保存到ArrayList中,JSP頁(yè)面希望表格輸出ArrayList對(duì)象,有兩種方法,有需要的朋友可以參考一下

一、UserAction中獲取到的ArrayList對(duì)象填充到UserForm中,jsp頁(yè)面獲取UserForm的初始值。
UserAction的部分代碼:

復(fù)制代碼 代碼如下:


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的部分代碼:

復(fù)制代碼 代碼如下:


private ArrayList userlist;
 public ArrayList getUserlist(){
  return userlist;
 }
 public void setUserlist(ArrayList userlist){
  this.userlist=userlist;
 }


JSP頁(yè)面代碼:

復(fù)制代碼 代碼如下:


    <table borderColor="darkgreen" cellSpacing="0">
    <logic:notEmpty property="userlist">
    <tr nowrap="nowrap">
    <td nowrap><b>用戶名</b></td>
    <td nowrap><b>角色</b></td>
    <td ><b>姓名</b></td>
    <td ><b>電話</b></td>
    <td ><b>電子郵件</b></td>
    <td ><b>動(dòng)作</b></td>
    </tr>
    <logic:iterate indexId="index" property="userlist">
    <tr>
      <td noWrap ><bean:write property="username"/></td>
      <td noWrap ><bean:write property="role"/></td>
      <td noWrap ><bean:write property="name"/></td>
      <td noWrap ><bean:write property="tel"/></td>
      <td noWrap ><bean:write property="email"/></td>
      <td nowrap sryle="width:273px" >
      <a href="javascript:submitSid(document.fview,'<bean:write property="username"/>')">查看</a>
      <font >||</font>
      <a href="javascript:submitSid(document.fview,'<bean:write property="username"/>')">更新</a>
      <font >||</font>
      <a href="javascript:if (confirm('刪除此用戶么?')){ submitSid(document.fview,'<bean:write property="username"/>')}">刪除</a>
      </td></tr>
      </logic:iterate>
      </logic:notEmpty>
      </table>


二、UserAction中獲取到數(shù)據(jù)ArrayList對(duì)象后,把ArrayList對(duì)象存在request中,JSP頁(yè)面在獲取到ArrayList對(duì)象。
UserAction部分代碼:

復(fù)制代碼 代碼如下:


 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部分代碼:

復(fù)制代碼 代碼如下:


<table  borderColor="darkgreen" cellSpacing="0">
    <tr >
    <td  ><b>用戶名</b></td>
    <td  ><b>角色</b></td>
    <td  ><b>姓名</b></td>
    <td  ><b>電話</b></td>
    <td ><b>電子郵件</b></td>
    <td ><b>動(dòng)作</b></td>
    </tr>
     <logic:present>
    <logic:iterate indexId="index" >
    <tr>
      <td   ><bean:write property="username"/></td>
      <td   ><bean:write property="role"/></td>
      <td  ><bean:write property="name"/></td>
      <td   ><bean:write property="tel"/></td>
      <td ><bean:write property="email"/></td>
      <td  >
      <a href="javascript:submitSid(document.fview,'<bean:write property="username"/>')">查看</a>
      <font >||</font>
      <a href="javascript:submitSid(document.fview,'<bean:write property="username"/>')">更新</a>
      <font >||</font>
      <a href="javascript:if (confirm('刪除此用戶么?')){ submitSid(document.fview,'<bean:write property="username"/>')}">刪除</a>
      </td></tr>
      </logic:iterate>
      </logic:present>
      </table>

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 法库县| 开封市| 江源县| 建阳市| 河南省| 田东县| 广河县| 建始县| 大余县| 广宁县| 乌恰县| 德钦县| 都安| 景宁| 城步| 新蔡县| 泌阳县| 云和县| 通河县| 且末县| 象州县| 苗栗县| 襄樊市| 商都县| 双柏县| 宁津县| 左云县| 泗水县| 临颍县| 福贡县| 措美县| 天等县| 洪湖市| 磴口县| 宝鸡市| 阜新市| 濮阳市| 汶上县| 沙洋县| 崇左市| 永泰县|