huangwmflymysky 于 2013.10.27 16:22 提问
- struts2下载不能弹出保存对话框的问题
-
前些天,写了一段代码,struts2下载的,但是无论我怎么改都不能弹出保存的对话框,在此向各位大神们求助了。代码如下
private String fileName; private ServletContext context; private InputStream inStream; private String mimeType; public String getFileName(){ try { return new String(fileName.getBytes(), "ISO8859-1"); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); return this.fileName; } } public void setFileName(String fileName) { try { this.fileName = new String(fileName.getBytes("ISO-8859-1"),"UTF-8"); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
public String download(){ mimeType = context.getMimeType(fileName); return "success"; } public InputStream getDownloadFile() throws UnsupportedEncodingException { String path = "/file/"; // 取得目录文件流返回。 inStream = context.getResourceAsStream(path+fileName); return inStream; } public void setServletContext(ServletContext context) { this.context = context; } public String getMimeType() { return mimeType; }
Struts的配置是:
downloadFile
${mimeType}
attachment;filename="${fileName}"
100000出现的情况为:
Content-Disposition:为空,什么都没有?
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!