I am using Struts2 file download for downloading a file from AS400 server.The file which i am downloading has CCSID 37(ebcdic) and when it is downloaded to PC it doesnot show anything just junk characters. When i display it on AS400 server its shows fine . Please suggest ! Help is appreciated!
jsp form :
<%@ 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>
Action class:
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;
}
}