• struts导出txt文件


    1、struts.xml 

    <action name="downLoad" class="org.wll.prj.action.HelloAction" method="exportFile">
            </action>

    2、export.jsp

     <script type="text/javascript">
        function daochu()
        {
       window.document.forms[0].submit();
        }
      </script>
      <body>
      <form action="<%=path%>/downLoad.action?method=exportFile" method="post">
          <input id="wll" name="wll" value="helloworld!"></input>
      </form>
        This is my JSP page. <br>
       
        <button onclick="daochu();">点击</button>
      </body>

    3、导出文件action

    public void exportFile() throws Exception {
      request = ServletActionContext.getRequest();
      response = ServletActionContext.getResponse();
      String[] ss = request.getParameterValues("wll");
      String filepath = "D://test.txt";
      response.setContentType("application/octet-stream; charset=gbk");
      response.setHeader("Content-disposition", "attachment; filename=\"" + filepath + "\"");
      PrintWriter pw = null;
      try {
       pw = response.getWriter();
       pw.print(ss[0]);            
       pw.println("");
      } catch (Exception e) {
       // TODO: handle exception
      }finally{
      }

    每一天都要行动,在前进中寻求卓越。
  • 相关阅读:
    除下草并推荐PhantomJS
    GTAC 2013
    Benchmark感受
    ChinaTest第二天
    "西厂"、"东厂"照片
    谈面试上
    mysql基本常用命令(转)
    java学习笔记数据类型、运算符和控制语句
    java学习笔记第一个applet程序以及一个小问题的解决
    网上阅卷系统自动识别功能代码
  • 原文地址:https://www.cnblogs.com/wshsdlau/p/2839790.html
Copyright © 2020-2023  润新知