struts下载搞了一天没搞定,用了smartupload

J2EE 码拜 9年前 (2015-05-11) 606次浏览 0个评论
 

SmartUpload su = new SmartUpload();
      try {
        su.initialize(this.getServlet().getServletConfig(),
                      httpServletRequest, httpServletResponse);
      }
      catch (ServletException ex2) {
      }
      su.setContentDisposition(null);
      try {
        su.downloadField(“USERNAME=adsfasdfasdf”,
                         “application/x-msdownload”, “k.txt”); //这个方法我改了,在jsp里是好用的!!!
      }
      catch (ServletException ex1) {
      }
      catch (IOException ex1) {
      }
      catch (SQLException ex1) {
      }
这是action的代码提示getOutputStream() has already been called for this response

2 如果把这段代码考到jsp里也不行!
org.apache.jasper.runtime.ServletResponseWrapperInclude.getOutputStream
有什么好的办法?在struts没有提供用户下载并转到自己要到页面的办法吗?

jsp里这样写的
<%
  SmartUpload su = new SmartUpload();
su.initialize(pageContext);
su.setContentDisposition(null);
su.downloadField(“adfasdfasdfasdf”,”application/x-msdownload”,”k.txt”);//这个方法我改过,单独的jsp是好使的
%>
这个问题没人搞定?
大家在struts 怎么实现下载的?
下载?还是上传?

下载的话
            response.setContentType(“application/octet-stream”);
            response.setHeader(“Content-Disposition”, “attachment; filename=”””
            ServletOutputStream out = response.getOutputStream();
然后用out.write()方法写文件内容

我要实现下载,用完上面这段的话,就没办法再转到需要的页面了!
下载是不能转到任何页面的(无论用什么技术)!
我是这样想的,想把数据先写到struts 要转到的页面,然后用javascript 来提供下载! 不知道这样可不可行

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明struts下载搞了一天没搞定,用了smartupload
喜欢 (0)
[1034331897@qq.com]
分享 (0)

文章评论已关闭!