本人新手.在做利用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 中的名字也改过来了。