struts2下载中文名文件问题
action:publicclassDownloadActionextendsActionSupport{privateStringfileName;publicStri...
action:
public class DownloadAction extends ActionSupport {
private String fileName;
public String getDownloadFileName() {
String fileName=ServletActionContext.getRequest().getParameter("fileName");
String downFileName = fileName;
try {
downFileName = new String(downFileName.getBytes("ISO-8859-1"), "UTF-8");
} catch (Exception e) {
e.printStackTrace();
}
return downFileName;
}
public InputStream getInputStream() {
String name=this.getDownloadFileName();
String realPath="/upload/"+name;
InputStream in=ServletActionContext.getServletContext().getResourceAsStream(realPath);
System.out.println(in);
if(null==in){
System.out.println("Can not find a java.io.InputStream with the name [inputStream] in the invocation stack. Check the <param name=\"inputName\"> tag specified for this action.检查action中文件下载路径是否正确.");
}
return ServletActionContext.getServletContext().getResourceAsStream(realPath);
}
@Override
public String execute() throws Exception {
return "SUCCESS";
}
public String getFileName() {
return fileName;
}
public void setFileName(String fileName) {
this.fileName = fileName;
}
struts:<action name="download" class="com.file.action.DownloadAction">
<result name="SUCCESS" type="stream">
<param name="contentType">application/octet-stream;
</param>
<param name="contentDisposition">
attachment;filename="${downFileName}"
</param>
<param name="inputName">inputStream</param>
<param name="bufferSize">4096</param>
</result>
</action>
下载时弹出框显示文件名是download.action,要怎么才能显示中文原名呢 展开
public class DownloadAction extends ActionSupport {
private String fileName;
public String getDownloadFileName() {
String fileName=ServletActionContext.getRequest().getParameter("fileName");
String downFileName = fileName;
try {
downFileName = new String(downFileName.getBytes("ISO-8859-1"), "UTF-8");
} catch (Exception e) {
e.printStackTrace();
}
return downFileName;
}
public InputStream getInputStream() {
String name=this.getDownloadFileName();
String realPath="/upload/"+name;
InputStream in=ServletActionContext.getServletContext().getResourceAsStream(realPath);
System.out.println(in);
if(null==in){
System.out.println("Can not find a java.io.InputStream with the name [inputStream] in the invocation stack. Check the <param name=\"inputName\"> tag specified for this action.检查action中文件下载路径是否正确.");
}
return ServletActionContext.getServletContext().getResourceAsStream(realPath);
}
@Override
public String execute() throws Exception {
return "SUCCESS";
}
public String getFileName() {
return fileName;
}
public void setFileName(String fileName) {
this.fileName = fileName;
}
struts:<action name="download" class="com.file.action.DownloadAction">
<result name="SUCCESS" type="stream">
<param name="contentType">application/octet-stream;
</param>
<param name="contentDisposition">
attachment;filename="${downFileName}"
</param>
<param name="inputName">inputStream</param>
<param name="bufferSize">4096</param>
</result>
</action>
下载时弹出框显示文件名是download.action,要怎么才能显示中文原名呢 展开
2013-12-10
展开全部
downFileName = new String(downFileName.getBytes("ISO-8859-1"), "UTF-8"槐颤);
系统是使用ISO-8859-1编码的?那中文肯定筹蔽亩码了宏明森。
统一使用GBK、或UTF-8编码
系统是使用ISO-8859-1编码的?那中文肯定筹蔽亩码了宏明森。
统一使用GBK、或UTF-8编码
更多追问追答
追问
系统页面用的UTF-8,但是这里不知道怎么改啊,总是不对啊
追答
那还由iso-8859-1转成UTF8,是UTF8就不用转了
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询