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

首頁 > 編程 > JSP > 正文

Action中ArrayList顯示到JSP頁面的具體實例

2020-07-27 21:36:31
字體:
來源:轉載
供稿:網(wǎng)友

一、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>

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 尼木县| 安吉县| 临安市| 渝中区| 郎溪县| 江口县| 汕头市| 彰化市| 四会市| 保靖县| 蓬安县| 兖州市| 荆州市| 邓州市| 隆化县| 陈巴尔虎旗| 建德市| 古交市| 陆川县| 滁州市| 如东县| 洛隆县| 临朐县| 光山县| 广州市| 武冈市| 枣强县| 富阳市| 平谷区| 沾化县| 湘潭市| 长兴县| 沙河市| 新河县| 姚安县| 上饶市| 武陟县| 平江县| 老河口市| 瑞丽市| 昌吉市|