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 οnclick="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{
??}
轉載于:https://www.cnblogs.com/wshsdlau/archive/2012/12/30/2839790.html
總結
以上是生活随笔為你收集整理的struts导出txt文件的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 如何用位移法解静定结构
- 下一篇: twiiq开发随笔(2)