在weblogic中,超级链接不能下载,而是直接打开,所以我用struts2的文件下载.
1.action 的名字必须为donwload;
2.action的配置如下:
<action name="download" class="subjectAction"> <!-- 给action注入inputPath(资源文件的位置) --> <param name="inputPath">/doc/myMianshiti.doc</param> <!-- 指输入流定流 --> <result name="success" type="stream"> <!-- 文件类型 --> <param name="contentType">application/msword</param> <!-- 下边的意思是说文件下载的输入流是"targetFile", struts2会调用它的get方法 也就是说实际是有getTargetFile输出流的内容的 --> <param name="inputName">targetFile</param> </result> </action>
3.action类中.必须有String inputPath,及其set方法;必须有getTargetFile方法返回流.(因为在配置文件中是这么指定的!)
返回流:return ServletActionContext.getServletContext().getResourceAsStream(inputPath);
4.补充:contentType 见:http://www.cnblogs.com/chenghm2003/archive/2008/10/19/1314703.html
转载于:https://www.cnblogs.com/yanjunwu/archive/2013/05/14/3078308.html
