struts2如何实现文件的下载

在文件上传的时,直接上传到了tomcat 工程下面,但是在实现文件下载时,这样获取路径:ServletContext servletContext=ServletActionContext.getServletContext(); String fileName=servletContext.getRealPath("/12.jpg");报错却是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. org.apache.struts2.dispatcher.StreamResult.doExecute(StreamResult.java:237) org.apache.struts2.dispatcher.StrutsResultSupport.execute(StrutsResultSupport.java:186)查看源码:if (inputStream == null) { // Find the inputstream from the invocation variable stack inputStream = (InputStream) invocation.getStack().findValue(conditionalParse(inputName, invocation)); } if (inputStream == null) { String msg = ("Can not find a java.io.InputStream with the name [" + inputName + "] in the invocation stack. " + "Check the <param name=尀"inputName尀"> tag specified for this action."); LOG.error(msg); throw new IllegalArgumentException(msg); } 应该是路径出错了!但是不知道怎么改!求助!
2026年09月19日 04:17
有1个网友回答
网友(1):

String fileName=servletContext.getRealPath("/12.jpg");
这个12.jpg是什么?应该放路径的,不是文件名