Structs2 文件下载

xiaoxiao2024-04-21  31

本人新手.在做利用Structs2 组件练习文件在载的时候,页面没有弹出保存的对话框,而是直接在页面上打开了文件的内容。现把相关代码描述如下:

DownloadAction.java

 public InputStream getInputStream()  {  System.out.println("=============");  return ServletActionContext.getServletContext().getResourceAsStream("/test/upFile/te.txt");  }  public String  test() {  System.out.println("======");  return "success"; }

 

structs.xml:

<action name="download" class="com.ssh.action.DownloadAction" method="test">    <result name="success" type="stream">     <!--<param name="contentType">text/plain</param>-->     <param name="contentDisponition">attachment;filename="struct2.txt"</param>     <param name="inputName">inputStream</param>     <param name="bufferSize">4096</param>    </result> </action>

 

JSP:

<body>  <center>  <s:a href="test/fileTest/download.action">保存</s:a>  </center> </body>

 

还个问题就是:如果我把Action 里面的方法 InputStream getInputStream() 改成 InputStream getDownloadFile() 的话,也会说我出错,错的原因是没找到路径。当然了,xml 中的名字也改过来了。

 

转载请注明原文地址: https://www.6miu.com/read-5015144.html

最新回复(0)