问题描述
- 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:为空,什么都没有?
时间: 2024-09-12 03:07:15