文件上传<三>

做文件下载时候碰到文件名乱码:
我的JSP,XML编码都是UTF-8的,Struts2也是默认的UTF-8,所以当时就觉得很郁闷,做上传的时候都没碰到.
后面上网查了下,改好了,但是还有疑惑:
之前我在处理中这样写:
ServletActionContext.getResponse().setHeader("Content-Disposition", "attachment; filename="+fileName);

结果在IE中没问题,但是在firefox中不出现 xxx.ppt, 多了个逗号,搞得我都郁闷惨了,最后搜文章才知道可以在action里面写个getXx(){},然后在struts.xml中用EL表达式获得此xx的值,唉,基础不好,真麻烦,在浮云上建高楼啊,不知道哪天就把自己给砸死...
唉...
Action:
public class DownLoadFileAction extends ActionSupport {
	
	public String getFileName() throws UnsupportedEncodingException{
		String fileName = "白盒测试";
		fileName = new String(fileName.getBytes("GB2312"),"iso-8859-1");
		return fileName;
	}
	
	public InputStream getDownLoadFile(){
		return ServletActionContext.getServletContext().getResourceAsStream("/upload/白盒测试.ppt");
	}
	@Override
	public String execute() throws Exception {
	    //ServletActionContext.getResponse().setHeader("Content-Disposition", "attachment; filename="+fileName);	    		
		return SUCCESS;
	}
}

xml配置:

<!-- 文件下载 -->
<action name="downloadFile" class="cwl.test.jstl.action.DownLoadFileAction">
<result name="success" type="stream">
<param name="contentDisposition ">attachment;filename="${fileName}.ppt"</param>
<param name="contentType">application/vnd.ms-powerpoint</param>
<param name="inputName">downLoadFile</param>
</result>
</action>

你可能感兴趣的:(xml,jsp,struts,IE,firefox)