栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

JSP页面中的Jasper报告

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

JSP页面中的Jasper报告

我已经编写了一个Struts(1.1)应用程序,可呈现PDF和CSV。我将在动作处理程序中执行此操作:

public ActionForward execute(ActionMapping mapping, ActionForm form,        HttpServletRequest request, HttpServletResponse response)        throws Exception {    response.setContentType("application/pdf");    OutputStream out = response.getOutputStream();    try {        // generate the PDF    } finally {        out.close();    }    return null; }

更新:将集合提供给JasperReports

package reports;import java.lang.reflect.Method;import java.util.Collection;import java.util.Iterator;import java.util.Arrays;import net.sf.jasperreports.engine.JRDataSource;import net.sf.jasperreports.engine.JRField;import net.sf.jasperreports.engine.JRException;public class CollectionDataSource implements JRDataSource {    private Iterator iterator = null;    private Object current = null;    public CollectionDataSource(Collection col) {        if (col != null) { iterator = col.iterator();        }    }    public CollectionDataSource(Object array[]) {        this(Arrays.asList(array == null ? new Object[0] : array));    }    public boolean next() throws JRException {        if (iterator == null || !iterator.hasNext()) { return false;        } else { current = iterator.next(); return true;        }    }    public Object getFieldValue(JRField field) throws JRException {        if ("this".equals(field.getName())) { return current;        } else if (current == null) { return null;        } else { Class<?> clazz = current.getClass(); char chars[] = field.getName().toCharArray(); chars[0] = Character.toUpperCase(chars[0]); String name = new String(chars); Method method = null; try {     method = clazz.getMethod("get" + name); } catch (NoSuchMethodException e) {     if (field.getValueClass() == Boolean.class) {         try {  method = clazz.getMethod("is" + name);         } catch (NoSuchMethodException e1) {         }     } } if (method == null) {     throw new JRException("No getter for field " + name); } try {     return method.invoke(current); } catch (Exception e) {     throw new JRException("Exception in getter of " + name, e); }        }    }}


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/422001.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号