主頁 > 知識(shí)庫 > Action中ArrayList顯示到JSP頁面的具體實(shí)例

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

熱門標(biāo)簽:團(tuán)購網(wǎng)站 銀行業(yè)務(wù) 科大訊飛語音識(shí)別系統(tǒng) 服務(wù)器配置 Linux服務(wù)器 阿里云 Mysql連接數(shù)設(shè)置 電子圍欄

一、UserAction中獲取到的ArrayList對(duì)象填充到UserForm中,jsp頁面獲取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頁面代碼:
復(fù)制代碼 代碼如下:

    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>動(dòng)作/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對(duì)象后,把ArrayList對(duì)象存在request中,JSP頁面在獲取到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 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>動(dòng)作/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>

標(biāo)簽:廣元 衡水 衢州 蚌埠 萍鄉(xiāng) 棗莊 江蘇 大理

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《Action中ArrayList顯示到JSP頁面的具體實(shí)例》,本文關(guān)鍵詞  ;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 收縮
    • 微信客服
    • 微信二維碼
    • 電話咨詢

    • 400-1100-266