0 0

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
  • 大小: 33 KB

1个答案 按时间排序 按投票排序

0 0

很不错,跑这上面来发帖来了,我也再找原因

2012年12月12日 11:26

相关推荐

Global site tag (gtag.js) - Google Analytics