String filePath=getRequest().getParameter("file"); String fileName = getRequest().getParameter("fileName"); String id = getRequest().getParameter("id"); filePath = getRequest().getRealPath("")+"\\"+"WordToPDF\\"+id+".pdf"; File f = new File(filePath); if(fileName==null){ fileName=id; } InputStream is=null; OutputStream os=null; try{ /**//*解决中文乱码问题,设置后产生一个新的String对象此对象以改变了编码*/ byte[] b=new byte[1024]; int i=0; is = new FileInputStream(f); os = getResponse().getOutputStream(); /**//*设置报头信息,弹出窗口中显示的文件名 newpath*/ getResponse().setCharacterEncoding("utf-8"); fileName = fileName+filePath.substring(filePath.lastIndexOf(".")); String agent = (String)getRequest().getHeader("USER-AGENT"); if(agent != null && agent.indexOf("MSIE") == -1) { // FF fileName = "=?UTF-8?B?" + (new String (Base64.encodeBase64(fileName.getBytes("UTF-8")))) + "?="; getResponse().setHeader("Content-Disposition", "attachment; filename=" + fileName); }else { // IE fileName = new String(fileName.getBytes("GBK"), "ISO-8859-1"); getResponse().setHeader("Content-Disposition", "attachment; filename=" + fileName); } //设置文件大小 getResponse().setContentLength((int) f.length()); /**//*具体的输入输出流操作*/ while((i=is.read(b))!=-1){ os.write(b, 0, i); } } catch (IOException e){ // TODO Auto-generated catch block e.printStackTrace(); }finally{ os.flush(); os.close(); is.close(); } /* if(f.exists()){ f.setWritable(true); f.delete(); } */
详细解决方案
Struts2资料流下载
热度:136 发布时间:2013-04-02 12:35:26.0
相关解决方案
- struts2.xml的action中的result报错,该怎么处理
- (Struts2+JSON+Ajax) XMLHttpRequest ==500如何解决
- struts2 对象属性流入不进去, 报错:target is null for setProperty(null, "x" [Ljava.lang.Stri
- Struts2 <select>上拉框 回显有关问题
- struts2 添加和修改怎么在一个jsp页面实现
- struts2 查询输出的有关问题
- 零配置的有关问题(struts2+Hibernate)
- struts2 神奇有关问题,太神奇了!
- struts2 的<s:iterator>标签展示未完全初始化的数组出现奇怪的有关问题
- struts2 文件下传有关问题
- struts2+ajax请求失败,帮忙看一上
- struts2-json中诠注@JSON(deserialize=false)是什么用?不是阻止JSON反序列化成JAVA对象吗?求解
- struts2 循环累加属性值有关问题
- struts2,hibernate,spring3 常用框架的API CHM版本,该怎么处理
- struts2 将jsp回到到另一个jsp中
- struts2 提交表单不能跳转页面有关问题!action已经执行,但是不能跳转到指定的页面
- struts2,hibernate,spring3 惯用框架的API CHM版本
- Struts2+Spring+JPA+FREEMARKER 登录程序异常
- struts2+Hibernate一个很奇怪的现象,该如何解决
- struts2 action中部分语句被直接跳过不执行. 请教这会是什么原因
- struts2+iReport 子表格 急需高手解决,已经困惑三天了!
- import cn.luxh.struts2.entity.Novel 急需的jar包是哪个
- struts2 hibernate 分页有关问题
- struts2 + spring 整合有关问题
- 请教哪里可以上到 struts2-json-plugin-2.1.8的源文件
- struts2+freemarker中文参数乱码有关问题
- struts2 exception,该怎么解决
- struts2 fileupload 下传有关问题
- struts2.3.4+spring3.1+mybats帮忙看看这个有关问题
- struts2 部署有关问题