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 对象属性流入不进去, 报错:target is null for setProperty(null, "x" [Ljava.lang.Stri
- Struts2 <select>上拉框 回显有关问题
- struts2 添加和修改怎么在一个jsp页面实现
- struts2 查询输出的有关问题
- struts2 神奇有关问题,太神奇了!
- struts2 的<s:iterator>标签展示未完全初始化的数组出现奇怪的有关问题
- struts2 文件下传有关问题
- struts2-json中诠注@JSON(deserialize=false)是什么用?不是阻止JSON反序列化成JAVA对象吗?求解
- struts2 将jsp回到到另一个jsp中
- struts2 提交表单不能跳转页面有关问题!action已经执行,但是不能跳转到指定的页面
- Struts2+Spring+JPA+FREEMARKER 登录程序异常
- struts2 action中部分语句被直接跳过不执行. 请教这会是什么原因
- struts2 hibernate 分页有关问题
- 请教哪里可以上到 struts2-json-plugin-2.1.8的源文件
- struts2+freemarker中文参数乱码有关问题
- struts2.3.4+spring3.1+mybats帮忙看看这个有关问题
- struts2 result的jsp页面怎么规定width和height
- struts2 调度后找不到页面 (404)急
- struts2 怎么修改Date数据
- struts2 +freemark+sitemesh css 失灵
- Struts2 <s:select/>有关问题
- struts2 交付同一表单,进行不同的action操作?
- Struts2.0作权限,要求控制到按钮级的,跪求思路以及数据库的设计
- struts2 表单中两个<s:submit>按钮,怎么能让一个按钮对应
- struts2 拦截器 和session 的存取有关问题
- struts2 拦截器不跳转
- struts2 加了拦截器后,发现不能页面传值,如何解决
- Struts2 接收Ajax post步骤传递参数, 领域模型只能接收第一个参数. 不知为何?
- struts2 <s:if>标签有关问题