zoukankan      html  css  js  c++  java
  • 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{
      }

    每一天都要行动,在前进中寻求卓越。
  • 相关阅读:
    mysql常见的优化方法
    Mac 怎么通过自带终端连接linux服务器
    基于 appium 的 UI 自动化测试
    sourcetree在mac上的使用
    mac下git安装和使用
    mac 上更改环境变量
    Mac环境下svn的使用
    jira常用配置
    influxDB基本操作
    Collectd 和 InfluxDB 的部署和使用
  • 原文地址:https://www.cnblogs.com/wshsdlau/p/2839790.html
Copyright © 2011-2022 走看看