【发布时间】:2014-04-02 16:52:42
【问题描述】:
我正在使用 Struts2 文件下载从 AS400 服务器下载文件。我正在下载的文件具有 CCSID 37(ebcdic),当它下载到 PC 时它不显示任何内容,只是垃圾字符。当我在 AS400 服务器上显示它时,它显示得很好。请建议! 感谢您的帮助!
jsp形式:
<%@ page contentType="text/html;charset=UTF-8" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>File Download</title>
</head>
<body>
<s:form action="/execFileDownload">
<s:textfield key="serverFiletobeDownload" label="Server File"/>
<s:submit value="Download"/>
</s:form>
</body>
</html>
struts.xml
<struts>
<constant name="struts.multipart.maxSize" value="2000000000" />
<package name="default" extends="struts-default">
<action name="execFileDownload" class="utils.action.FileDownloadAction">
<result name="success" type="stream">
<param name="contentType">application/octet-stream</param>
<param name="inputName">inputStream</param>
<param name="contentDisposition">attachment;filename="${fileName}"</param>
<param name="bufferSize">4096</param>
</result>
</action>
<struts>
动作类:
public class FileDownloadAction extends ActionSupport {
private static final long serialVersionUID = 1L;
private InputStream inputStream;
private long contentLength;
private String fileName;
public InputStream getInputStream() {
return inputStream;
}
public long getContentLength() {
return contentLength;
}
public String getFileName() {
return fileName;
}
private String serverFiletobeDownload;
public String getServerFiletobeDownload() {
return serverFiletobeDownload;
}
public void setServerFiletobeDownload(String serverFiletobeDownload) {
this.serverFiletobeDownload = serverFiletobeDownload;
}
public String execute() throws FileNotFoundException {
File fileToDownload = new File(serverFiletobeDownload.trim());
inputStream = new FileInputStream(fileToDownload);
fileName = fileToDownload.getName();
contentLength = fileToDownload.length();
return SUCCESS;
}
}
【问题讨论】:
-
您是否检查了各个字符字段是否为 ccsid 37?
-
我正在尝试复制 ifs 文件文本、pdf 等
-
啊,是的。如果我阅读了您的代码,我可以看到这一点。
-
如何“在 AS400 服务器上显示”?这可能会导致更多问题。
-
IFS 中的 PDF 的 CCSID 不应为 37。5348 或 1252 会更有意义。一个普通的 .TXT 可能有 37 的 CCSID。但您的下载过程必须翻译它。对于 .TXT 文件,系统可以配置为从某些接口自动翻译。但我不知道STRUTS 使用的是什么。我的猜测是它正在进行二进制下载。最好的解决方案是首先将文件输出为 ASCII。
标签: java jsp encoding struts2 ibm-midrange