diff --git a/WebContent/Frame/page/js/as_control.js b/WebContent/Frame/page/js/as_control.js index 71c90f517..8ee88dd66 100644 --- a/WebContent/Frame/page/js/as_control.js +++ b/WebContent/Frame/page/js/as_control.js @@ -466,7 +466,7 @@ AsControl.ExportFinanceReport = function(sObjectType, sObjectNo, sReportScope, s var sReportExcelPath = AsControl.RunJavaMethodSqlca("com.amarsoft.app.util.ExportExcel", "run", sParam); if(!sReportExcelPath) return; if(!frames["exportfsframe"]) $("").appendTo("body"); - window.open(sWebRootPath+"/servlet/view/file?CompClientID="+sCompClientID+"&filename="+sReportExcelPath+"&viewtype=download", "exportfsframe"); + window.open(sWebRootPath+"/servlet/view/file1?CompClientID="+sCompClientID+"&filename="+sReportExcelPath+"&viewtype=download", "exportfsframe"); }; AsControl.CallJavaMethodJSP = function (ClassName,MethodName,Args,ArgsObjectText) { diff --git a/WebContent/Tenwa/Lease/Flow/Comm/LBContractTemplate/TraditionContractFileList.jsp b/WebContent/Tenwa/Lease/Flow/Comm/LBContractTemplate/TraditionContractFileList.jsp index 5e8e59aff..1d3a9a323 100644 --- a/WebContent/Tenwa/Lease/Flow/Comm/LBContractTemplate/TraditionContractFileList.jsp +++ b/WebContent/Tenwa/Lease/Flow/Comm/LBContractTemplate/TraditionContractFileList.jsp @@ -18,7 +18,7 @@ dwTemp.Style="1"; //--设置为Grid风格-- dwTemp.ReadOnly = "1"; //只读模式 dwTemp.setPageSize(10); - dwTemp.genHTMLObjectWindow(flowunid); + dwTemp.genHTMLObjectWindow(contractid);//原是对应attr.flowunid String button = "false"; if("0010".equals(phaseno)){ diff --git a/WebContent/WEB-INF/web.xml b/WebContent/WEB-INF/web.xml index 318abcf2f..c20b734cf 100644 --- a/WebContent/WEB-INF/web.xml +++ b/WebContent/WEB-INF/web.xml @@ -206,6 +206,10 @@ FileViewServlet com.amarsoft.awe.common.attachment.FileViewServlet + + FileViewServlet1 + com.tenwa.lease.util.FileViewServlet + ShowImageServlet com.tenwa.doc.servlet.ShowImageServlet @@ -308,6 +312,10 @@ FileViewServlet /servlet/view/file + + FileViewServlet1 + /servlet/view/file1 + ShowImageServlet /servlet/view/image @@ -565,6 +573,7 @@ /resf/files/downloadPlist, /resf/files/downloadApp, /resf/files/downloadAppById, + /servlet/view/file1, diff --git a/src/com/amarsoft/app/util/ExportExcel.java b/src/com/amarsoft/app/util/ExportExcel.java index 0e016e328..b9134678a 100644 --- a/src/com/amarsoft/app/util/ExportExcel.java +++ b/src/com/amarsoft/app/util/ExportExcel.java @@ -3,6 +3,8 @@ package com.amarsoft.app.util; import java.awt.Color; import java.io.File; import java.io.FileOutputStream; +import java.io.OutputStreamWriter; +import java.net.URLEncoder; import java.util.ArrayList; import java.util.List; @@ -88,7 +90,8 @@ public class ExportExcel List boRC = null; //根据报表编号找出对应的报表 if(reportScope != null){ - sFileName = sDirPath + "/" + this.objectType + "-" + this.objectNo + "-" + this.reportScope + "-" + this.reportDate.replace("/", "") + "-" + String.valueOf(Math.random()).replace(".", "") + ".xlsx"; + + sFileName = sDirPath + "/" +NameManager.getCustomerName(this.objectNo)+"-"+ this.reportDate.replace("/", "") +".xlsx";//this.objectType + "-" + this.objectNo + "-" + this.reportScope + "-" + this.reportDate.replace("/", "") + "-" + String.valueOf(Math.random()).replace(".", "") + ".xlsx"; boRC = JBOFactory.getBizObjectManager(REPORT_RECORD.CLASS_NAME).createQuery("objecttype=:ObjectType and reportscope=:ReportScope and reportdate=:ReportDate and objectno=:ObjectNo order by modelno") .setParameter("ObjectType", objectType) .setParameter("ReportScope", reportScope) @@ -405,7 +408,9 @@ public class ExportExcel } } } +// String codedfilename = URLEncoder.encode(sFileName, "UTF-8");//.replaceAll("+", "%20"); FileOutputStream fos = new FileOutputStream(sFileName); +// OutputStreamWriter oStreamWriter = new OutputStreamWriter(fos, "gbk"); excel.write(fos); fos.flush(); fos.close(); diff --git a/src_tenwa/com/tenwa/lease/util/FileViewServlet.java b/src_tenwa/com/tenwa/lease/util/FileViewServlet.java new file mode 100644 index 000000000..6928748fa --- /dev/null +++ b/src_tenwa/com/tenwa/lease/util/FileViewServlet.java @@ -0,0 +1,116 @@ +package com.tenwa.lease.util; + +import java.io.File; +import java.io.FileInputStream; +import java.io.InputStream; +import java.net.URLEncoder; + +import javax.servlet.ServletException; +import javax.servlet.ServletOutputStream; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; + +import com.amarsoft.are.ARE; +import com.amarsoft.are.util.DataConvert; + +public class FileViewServlet extends javax.servlet.http.HttpServlet{ + + private static final long serialVersionUID = 1L; + + public FileViewServlet() {} + + public void service(HttpServletRequest request, HttpServletResponse response) + throws ServletException, java.io.IOException { + try { + HttpSession session = request.getSession(true); + if ((session == null) || (session.getAttributeNames() == null)) { + throw new Exception("------Timeout------"); + } + String sFileName = ""; + String sContentType = "text/html"; + String sViewType = "view"; + + sFileName = DataConvert.toString(request.getParameter("filename")); + sFileName = new String(sFileName.getBytes("iso-8859-1")); + sContentType = DataConvert.toString(request + .getParameter("contenttype")); + sViewType = DataConvert.toString(request.getParameter("viewtype")); + + ARE.getLog().debug( + "[FileViewServlet]" + sContentType + ":" + sFileName); + + if (sFileName.indexOf("../") >= 0) { + ARE.getLog().warn("[FileViewServlet-ERR]文件名包含非法参数!"); + return; + } + File dFile = null; + dFile = new File(sFileName); + if (!dFile.exists()) { + ARE.getLog().warn( + "[FileViewServlet-ERR]文件不存在:" + sFileName + "!"); + String sCon = "文件不存在 !"; + ServletOutputStream outStream = response.getOutputStream(); + outStream.println(DataConvert.toRealString(3, sCon)); + outStream.flush(); + outStream.close(); + } else { + String sNewFileName = com.amarsoft.are.util.StringFunction + .getFileName(sFileName); + String browName = sNewFileName; + String clientInfo = request.getHeader("User-agent"); + if (clientInfo != null) { + if (clientInfo.indexOf("MSIE") > 0) { + if ((clientInfo.indexOf("MSIE 6") > 0) + || (clientInfo.indexOf("MSIE 5") > 0)) { + browName = new String(sNewFileName.getBytes("GBK"), + "ISO-8859-1"); + } else { + browName = URLEncoder.encode(sNewFileName, "UTF-8"); + } + } else if (clientInfo.indexOf("Chrome") > 0) { + browName = URLEncoder.encode(sNewFileName, "UTF-8"); + } else if (clientInfo.indexOf("Firefox") > 0) { + browName = new String(sNewFileName.getBytes("UTF-8"), + "ISO-8859-1"); + } + } + response.setContentType(sContentType + ";charset=GBK"); + if (sViewType.equals("view")) { + response.setHeader("Content-Disposition", "filename=" + + browName + ";"); + } else { + response.setHeader("Content-Disposition", + "attachment;filename=" + browName + ";"); + } + int iContentLength = (int) dFile.length(); + if (iContentLength > 0) { + ServletOutputStream outStream2 = response.getOutputStream(); + InputStream inStream = new FileInputStream(sFileName); + + if (iContentLength > 102400) + iContentLength = 102400; + byte[] abyte0 = new byte[iContentLength]; + int k = -1; + while ((k = inStream.read(abyte0, 0, iContentLength)) != -1) { + if (k >= 10240) { + ARE.getLog().debug("[FileViewServlet]Read:" + k); + } + outStream2.write(abyte0, 0, k); + } + inStream.close(); + + outStream2.flush(); + outStream2.close(); + } + return; + } + } catch (Exception e1) { + e1 = e1; + ARE.getLog().error("[FileViewServlet-ERR]", e1); + } finally { + } + } + + public String getServletInfo() { return "This is a file view servlet!"; } +}