Struts2 文件下载 导致的怪异问题~【项目不断报错】
2012-5-31 13:32:58 org.apache.catalina.core.AprLifecycleListener init信息: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: E:\Java\jdk1.6.0_20\bin;E:\Tomcat6.0\bin2012-5-31 13:32:58 org.apache.coyote.http11.Http11Protocol init信息: Initializing Coyote HTTP/1.1 on http-80802012-5-31 13:32:58 org.apache.catalina.startup.Catalina load信息: Initialization processed in 560 ms信息: JK: ajp13 listening on /0.0.0.0:80092012-5-31 13:33:10 org.apache.jk.server.JkMain start信息: Jk running ID=0 time=0/31 config=null2012-5-31 13:33:10 org.apache.catalina.startup.Catalina start信息: Server startup in 12239 ms
null检查action中文件下载路径是否正确.2012-5-31 13:35:21 com.opensymphony.xwork2.util.logging.commons.CommonsLogger error严重: Can not find a java.io.InputStream with the name [inputStream] in the invocation stack. Check the <param name="inputName"> tag specified for this action.null检查action中文件下载路径是否正确.2012-5-31 13:35:21 com.opensymphony.xwork2.util.logging.commons.CommonsLogger error严重: Can not find a java.io.InputStream with the name [inputStream] in the invocation stack. Check the <param name="inputName"> tag specified for this action.2012-5-31 13:35:21 com.opensymphony.xwork2.util.logging.commons.CommonsLogger error严重: Can not find a java.io.InputStream with the name [inputStream] in the invocation stack. Check the <param name="inputName"> tag specified for this action.null检查action中文件下载路径是否正确.null检查action中文件下载路径是否正确.2012-5-31 13:35:31 com.opensymphony.xwork2.util.logging.commons.CommonsLogger error严重: Can not find a java.io.InputStream with the name [inputStream] in the invocation stack. Check the <param name="inputName"> tag specified for this action.null检查action中文件下载路径是否正确.2012-5-31 13:35:31 com.opensymphony.xwork2.util.logging.commons.CommonsLogger error严重: Can not find a java.io.InputStream with the name [inputStream] in the invocation stack. Check the <param name="inputName"> tag specified for this action.null检查action中文件下载路径是否正确.2012-5-31 13:35:31 com.opensymphony.xwork2.util.logging.commons.CommonsLogger error严重: Can not find a java.io.InputStream with the name [inputStream] in the invocation stack. Check the <param name="inputName"> tag specified for this action.
public class DownloadActionTrue extends ActionSupport { /** * generate serialVersionUID */ private static final long serialVersionUID = -1502162994976647682L; // 下载文件原始存放路径 private final static String DOWNLOADFILEPATH = "/upload/"; // 文件名参数变量 private String fileName; public String getFileName() { return fileName; } public void setFileName(String fileName) throws UnsupportedEncodingException { this.fileName = fileName; } @Override public String execute() throws Exception { return SUCCESS; } // 从下载文件原始存放路径读取得到文件输出流 public InputStream getInputStream() throws Exception { String realPath = DOWNLOADFILEPATH + fileName; InputStream inputStream = ServletActionContext.getServletContext() .getResourceAsStream(realPath); System.out.println(inputStream); if (null == inputStream) { System.out.println("检查action中文件下载路径是否正确."); } return inputStream; } // 如果下载文件名为中文,进行字符编码转换 public String getDownloadFileName() { String downFileName = fileName; try { downFileName = new String(downFileName.getBytes("iso-8859-1")); System.out.println(downFileName); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } return downFileName; } }
<action name="download" class="com.yaxing.action.DownloadActionTrue" > <!-- 设置文件名参数,由页面上传入 --> <param name="fileName"></param> <result name="success" type="stream"> <!-- 下载文件输出流定义 --> <param name="inputName"></param> <!-- 下载文件类型定义 --> <param name="contentType">text/plain,application/pdf,application/msword,application/vnd.ms-powerpoint, image/bmp, image/gif,image/jpeg,image/jpeg,image/png, text/html,text/html, application/octet-stream ,application/zip;charset=ISO8859-1 </param> <!-- 使用经过转码的文件名作为下载文件名,downloadFileName属性 对应action类中的方法 getDownloadFileName() --> <param name="contentDisposition"> attachment;filename="${downloadFileName}" </param> </result> </action>
2012-5-31 13:38:12 org.apache.catalina.core.StandardWrapperValve invoke严重: Servlet.service() for servlet default threw exceptionjava.lang.IllegalStateException at org.apache.catalina.connector.ResponseFacade.sendError(ResponseFacade.java:407) at org.apache.struts2.dispatcher.Dispatcher.sendError(Dispatcher.java:819) at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:519) at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77) at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:198) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588) at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489) at java.lang.Thread.run(Thread.java:619)
java.lang.IllegalArgumentException: Can not find a java.io.InputStream with the name [inputStream] in the invocation stack. Check the <param name="inputName"> tag specified for this action.