一段可以使用的 hibernate获得对象->action存入List->jsp页面用<s:iterator>迭代的代码...

使用SelectService获取报告列表并展示
本文介绍了一个名为SelectAction的Java类,它通过SelectService接口获取报告列表,并将这些列表通过toReportGetter方法进行处理,最后在select.jsp页面上以表格形式展示出来。

SelectAction.java

 1 @SuppressWarnings("serial")
 2 @Component("selectAction")
 3 @Scope("prototype")
 4 public class SelectAction extends BaseAction{
 5 
 6     private ISelectService selectService;
 7     
 8     @Resource
 9     public void setSelectService(ISelectService selectService) {
10         this.selectService = selectService;
11     }
12     
13     public List<ReportFormBeans> reportlist; 
14     public List<ReportFormBeans> getReportlist(){
15          return reportlist;
16          }
17     public void setReportlist(List<ReportFormBeans> reportlist) {
18          this.reportlist = reportlist;
19          }
20     
21     public String toReportGetter()throws Exception
22     {
23         
24     try {
25         
26          List<ReportFormBeans> list = new ArrayList<ReportFormBeans>();
27 
28             int i = 1;
29             int max = selectService.getReportCount();
30             
31             while(i <= max){
32                 ReportFormBeans reportFormBean = new ReportFormBeans();
33                 BeanUtils.copyProperties(reportFormBean , selectService.getReport(i));
34                 list.add(reportFormBean); 
35 
36                 for (int j = 0; j < list.size(); j++) {
37                     System.out.println(list.get(j));
38                 }
39 
40                 i++;
41             }                        
42             this.setReportlist(list);
43             return SUCCESS;            
44         } catch (Exception e) {
45             e.printStackTrace();
46             System.out.println("ERROR!");
47             return INPUT;
48         }
49     }
50 }

select.jsp

 1 <%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
 2 <%@ taglib prefix="s" uri="/struts-tags" %>
 3 
 4 <%
 5 String path = request.getContextPath();
 6 String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
 7 %>
 8 
 9 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
10 <html>
11   <head>
12     <base href="<%=basePath%>">
13     <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
14     <title>注册页面</title>
15     <meta http-equiv="pragma" content="no-cache">
16     <meta http-equiv="cache-control" content="no-cache">
17     <meta http-equiv="expires" content="0">    
18     <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
19     <meta http-equiv="description" content="This is my page">
20     <!--
21     <link rel="stylesheet" type="text/css" href="styles.css">
22     -->
23   </head>
24   <body>
25     <s:iterator value="reportlist"> 
26     <tr> 
27         <td><s:property value="sid"/></td>
28     </tr> 
29     </s:iterator> 
30     <s:debug/>
31   </body>
32 </html>

 

转载于:https://www.cnblogs.com/liuxiaoke/p/3457165.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值