-
jasperreport+struts导出pdf文件,部分浏览器无法下载10
最近在做一个项目的财务单据打印,业主要求生产pdf格式的文件然后打印
jasperreport用的是4.0.1
struts配置的是2.0.9
struts配置:
<action name="createStokeInPDF" method="createStokeInPDF" class="createPdfAction">
<result name="success" type="jasper">
<!-- 编译后的jasper文件路径 -->
<param name="location">/report/${styleType}.jasper</param>
<!-- 视图界面中显示的数据的数据源 -->
<param name="dataSource">stokeInList</param>
<!-- 报表生成格式 -->
<param name="format">PDF</param>
<param name="documentName">${fileName}</param>
</result>
<result name="error">/jsp/error.jsp</result>
</action>
action代码:
package com.freshpower.bid.report.action;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import com.freshpower.bid.ma.model.MaterialClass;
import com.freshpower.bid.mf.biz.MFBillMgr;
import com.freshpower.bid.mf.biz.MFMaterialMgr;
import com.freshpower.bid.mf.biz.MFReportMgr;
import com.freshpower.bid.mf.model.MFStoreBill;
import com.freshpower.bid.mf.model.MaterialStore;
import com.freshpower.bid.report.model.StokeInBean;
import com.opensymphony.xwork2.ActionSupport;
public class CreatePDFAction extends ActionSupport{
private static final long serialVersionUID = 1L;
private List<StokeInBean> stokeInList = new ArrayList<StokeInBean> ();
private StokeInBean stokeIn;
private String idtemp;
private String printType;
private MFMaterialMgr mfmaterialmgr;
private MFBillMgr mfbillmgr;
private MFReportMgr mfreportmgr;
private String fileName;
private String styleType;
/**
* 取到入库验收信息
* @return
* @throws Exception
*/
private StokeInBean getStockInDateSouce() throws Exception{
try{
MFStoreBill stbill = new MFStoreBill();
stbill.setStoreBillId(Long.valueOf(idtemp));
stbill=this.mfbillmgr.getMFStoreBillById(stbill);
MaterialStore mastore = new MaterialStore();
mastore.setLinkId(Long.valueOf(idtemp));
List<MaterialStore> mastoreList = this.mfmaterialmgr.getList(mastore, "getAllMaterialStore");
mastore=mastoreList.get(0);
stokeIn = new StokeInBean();
stokeIn.setTitleName(getInTitleName(printType));
stokeIn.setProjectName(stbill.getProjectName());
stokeIn.setStationName(stbill.getSendPlace());
stokeIn.setMaterialType(mastore.getMaterialNo());
stokeIn.setSignDate(new SimpleDateFormat("yyyy-MM-dd").format(stbill.getSignDate()));
stokeIn.setBillNo(stbill.getStoreBillNo());
stokeIn.setSendUnit(stbill.getSendPlace());
stokeIn.setArriveNo(stbill.getSendNo());
stokeIn.setReceiveDate(new SimpleDateFormat("yyyy-MM-dd").format(stbill.getGetMFDate()));
if(stbill.getCreateDate()!=null){
stokeIn.setCreateDate(new SimpleDateFormat("yyyy-MM-dd").format(stbill.getCreateDate()));
}else{
stokeIn.setCreateDate(stokeIn.getSignDate());
}
stokeIn.setProviderName(stbill.getProviderName());
stokeIn.setPactNo(stbill.getPactNo());
if(stbill.getCarNo()!=null){
stokeIn.setCarNo(stbill.getCarNo());
}else{
stokeIn.setCarNo("");
}
stokeIn.setMaterialType(coverMaterialType(mastore.getMaterialNo()));
stokeIn.setMaterialNo(mastore.getMaterialNo());
if(mastore.getMaterialSpec()==null){
mastore.setMaterialMade("");
}
if(mastore.getMaterialType()==null){
mastore.setMaterialType("");
}
stokeIn.setMaterialDetail(mastore.getMaterialName()+" "+mastore.getMaterialSpec()+ " "+mastore.getMaterialType());
stokeIn.setMaterialUnit(mastore.getMaterialUnit());
stokeIn.setShouldAcount(mastore.getMaterialAcount());
stokeIn.setInfactAcount(mastore.getMaterialAcount());
stokeIn.setPlanPrice(mastore.getPlanPrice());
stokeIn.setPlanMoney(mastore.getPlanMoney());
stokeIn.setStationManager(stbill.getStationManager());
stokeIn.setKeeper(stbill.getKeeper());
stokeIn.setBillMaker(stbill.getBillMaker());
if(mastore.getSendmId()!=null){
MaterialSend send = new MaterialSend();
send.setMaterialId(mastore.getSendmId());
send=this.mfmaterialmgr.getMaterialSendById(send);
stokeIn.setShouldAcount(send.getMaterialAcount());
}else{
stokeIn.setShouldAcount(stokeIn.getInfactAcount());
}
if(isGangGuan(stokeIn.getMaterialNo())){//如果是钢管 计算 件数长度
stokeIn.setInfactLength("");
stokeIn.setShouldLength("");
stokeIn.setShouldRoot("");
if(mastore.getMaterialRoot()!=null){
stokeIn.setInfactRoot(mastore.getMaterialRoot());
}else{
stokeIn.setInfactRoot("");
}
}
if(stbill.getNotes()==null){
stokeIn.setNotes("");
}else{
stokeIn.setNotes(stbill.getNotes());
}
//导出的文件名
//fileName=stbill.getProjectName()+mastore.getMaterialName()+"物资验收单";
fileName=stbill.getStoreBillNo();
return stokeIn;
}catch(Exception e){
e.printStackTrace();
return null;
}
}
/**
* 打印入库验收单
* @return
* @throws Exception
*/
public String createStokeInPDF() throws Exception {
if(printType.equals("4")){
for(int i=0;i<3;i++){
stokeIn=getStockInDateSouce();//取到数据源
stokeIn.setTitleName(getInTitleName(String.valueOf(i+1)));
stokeInList.add(stokeIn);
}
}else{
stokeIn=getStockInDateSouce();//取到数据源
stokeIn.setTitleName(getInTitleName(printType));
stokeInList.add(stokeIn);
}
getInStyleType(stokeIn);
return SUCCESS;
}
/**
*
* @param printType
* @return
*/
public String getInTitleName(String printType){
String result="";
if(printType.equals("1")){
result="一 制单存";
}
if(printType.equals("2")){
result="二 财务记帐";
}
if(printType.equals("3")){
result="三 采办处";
}
if(printType.equals("4")){
result="全套三联";
}
return result;
}
/**
* 得到返回结果(打印样板文件名称)
* @return
*/
public void getInStyleType(StokeInBean stokeIn){
String pro = stokeIn.getProjectName();
String notemp=stokeIn.getMaterialNo().substring(0,4);
if(pro.equals("中卫-贵阳联络线(渝黔段)及支线管道工程(六标段)")){//中贵六标格式
if(notemp.equals("0309")||notemp.equals("0310")){//如果是钢管
//styleType="stoke_in_zg6_0309";
styleType="stoke_in_zg6_0309";
}else{ //如果不是钢管
styleType="stoke_in_zg6_other";
}
}
else{//老系统格式
if(notemp.equals("0309")||notemp.equals("0310")){//如果是钢管
styleType="stoke_in_old_0309";
}else{ //如果不是钢管
styleType="stoke_in_old_other";
}
}
}
//-------------------------------------
public List<StokeInBean> getStokeInList() {
return stokeInList;
}
public void setStokeInList(List<StokeInBean> stokeInList) {
this.stokeInList = stokeInList;
}
public String getIdtemp() {
return idtemp;
}
public void setIdtemp(String idtemp) {
this.idtemp = idtemp;
}
public String getPrintType() {
return printType;
}
public void setPrintType(String printType) {
this.printType = printType;
}
public MFMaterialMgr getMfmaterialmgr() {
return mfmaterialmgr;
}
public void setMfmaterialmgr(MFMaterialMgr mfmaterialmgr) {
this.mfmaterialmgr = mfmaterialmgr;
}
public MFBillMgr getMfbillmgr() {
return mfbillmgr;
}
public void setMfbillmgr(MFBillMgr mfbillmgr) {
this.mfbillmgr = mfbillmgr;
}
public StokeInBean getStokeIn() {
return stokeIn;
}
public void setStokeIn(StokeInBean stokeIn) {
this.stokeIn = stokeIn;
}
public String getFileName() {
return fileName;
}
public void setFileName(String fileName) {
this.fileName = fileName;
}
public MFReportMgr getMfreportmgr() {
return mfreportmgr;
}
public void setMfreportmgr(MFReportMgr mfreportmgr) {
this.mfreportmgr = mfreportmgr;
}
public StokeOutBean getStokeout() {
return stokeout;
}
public void setStokeout(StokeOutBean stokeout) {
this.stokeout = stokeout;
}
public String getStyleType() {
return styleType;
}
public void setStyleType(String styleType) {
this.styleType = styleType;
}
public List<StokeOutBean> getStokeOutList() {
return stokeOutList;
}
public void setStokeOutList(List<StokeOutBean> stokeOutList) {
this.stokeOutList = stokeOutList;
}
}
导出的话ie9和谷歌浏览器没有问题,部分浏览器比如ie6,ie7,ie8导出的时候页面空白什么都不显示,
截图入下
360浏览器部分电脑上可以下载,部分电脑不能下载
最开始的时候多点几次 tomcat服务器直接内存溢出了,在网上找了相关文件是
导出pdf报表的时候容易内存溢出
因为pdf文件过大导致的
修改一下tomcat配置即可解决
-Xms512m -Xmx512m -XX:MaxNewSize=512m -XX:MaxPermSize=512m
现在内存溢出问题解决了,但是很多用户正常使用的浏览器无法导出pdf文件,用户的使用很不方便而且满意度差
一直苦苦钻研不知道原因何在,
希望各位前辈和高手不吝赐教,帮我解决问题!
qq:312383161
2012年11月25日 10:24
相关推荐
jasperreport+struts2包 可以使用
一个完整的jasperreport+myeclipse+struts2例子,方便大家学习
NULL 博文链接:https://aokunsang.iteye.com/blog/1388696
Struts2.0+JasperReport+IReport+Oracle 报表开发 整个项目打包上传,用MyEclipse导入即可调试使用 含报表文件、数据库表结构及测试数据,项目中解决了PDF中文不显示问题
使用JasperReport+iReport进行WEB开发,是这篇文章http://blog.csdn.net/tch918/article/details/12200607的源码
JasperReport+struts+spring+hibernate+extjs4.1
该工程下有ssh所需jar包,hicharts报表导出功能所需jar包,以及Jasperreport报表导出所需的jar包,主要是利用Jasperreport实现报表导出功能,可以完整跑通
jasperreport+ireport+jfreechart文档及代码1 jasperreport+ireport+jfreechart文档及代码1 jasperreport+ireport+jfreechart文档及代码1
jasperreport+ireport+jfreechart文档及代码2 jasperreport+ireport+jfreechart文档及代码2 jasperreport+ireport+jfreechart文档及代码2
NULL 博文链接:https://hewei5894.iteye.com/blog/1744757
Struts2.0+JasperReport+IReport+Oracle 报表开发 整个项目打包上传,用MyEclipse导入即可调试使用 含报表文件、数据库表结构及测试数据,项目中解决了PDF中文不显示问题
Struts2.0+JasperReport+IReport+Oracle 报表开发整个项目打包上传,用MyEclipse导入即可调试使用含报表文件、数据库表结构及测试数据,项目中解决了PDF中文
学习完jasperreports+ireport,给我感觉深刻,不仅掌握了报表开发技术,还掌握了如何在web中生成pdf,xls,rtf文件,以下是jasperreports+ireport开发知识点: 1.字段,变量,参数,传参 2.矢量图,位图 3.超链接,锚 4.数据源,...
JasperReport+iReport报表开发手册.pdf
jasperreport_ireport+struts2打印报表
jasperReport例,jasperReport+java
JasperReports 是一个强大、灵活的报表生成工具,能够展示丰富的页面内容,并将之转换 成 PDF,HTML,或者 XML 格式。...总的而言,JasperReports 主要分成三个部分,包括数据报表 设计、数据填充与数据报表导出。
struts jasperreport ireport5.0 字报表数据传递 子报表路径问题 中文问题
JasperReport+iReport打印固定格式文件的测试工程源码