修改导出财报乱码无法导出问题

This commit is contained in:
jianghongdong 2018-09-26 17:26:35 +08:00
parent 722147b0d5
commit 6a146b9fab
5 changed files with 133 additions and 3 deletions

View File

@ -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"]) $("<iframe name='exportfsframe' style='display:none;'></iframe>").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) {

View File

@ -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)){

View File

@ -206,6 +206,10 @@
<servlet-name>FileViewServlet</servlet-name>
<servlet-class>com.amarsoft.awe.common.attachment.FileViewServlet</servlet-class>
</servlet>
<servlet>
<servlet-name>FileViewServlet1</servlet-name>
<servlet-class>com.tenwa.lease.util.FileViewServlet</servlet-class>
</servlet>
<servlet>
<servlet-name>ShowImageServlet</servlet-name>
<servlet-class>com.tenwa.doc.servlet.ShowImageServlet</servlet-class>
@ -308,6 +312,10 @@
<servlet-name>FileViewServlet</servlet-name>
<url-pattern>/servlet/view/file</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>FileViewServlet1</servlet-name>
<url-pattern>/servlet/view/file1</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>ShowImageServlet</servlet-name>
<url-pattern>/servlet/view/image</url-pattern>
@ -565,6 +573,7 @@
/resf/files/downloadPlist,
/resf/files/downloadApp,
/resf/files/downloadAppById,
/servlet/view/file1,
</param-value>
</init-param>
<init-param>

View File

@ -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<BizObject> 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();

View File

@ -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!"; }
}