大家帮忙看看这个问题怎么解决?非常感谢!(I)这是Tomcat报的exception:
2010-3-29 16:11:26 com.opensymphony.xwork2.util.logging.commons.CommonsLogger error
严重: Can not find a java.io.InputStream with the name [targetFile] in the invocation stack. Check the <param name="inputName"> tag specified for this action.
(II)这是浏览器报的exception:
Struts has detected an unhandled exception: Messages: Can not find a java.io.InputStream with the name [targetFile] in the invocation stack. Check the tag specified for this action.
File: org/apache/struts2/dispatcher/StreamResult.java
Line number: 237
(III)这是我的struts.xml
<package name="download" extends="struts-default">
<action name="download" class="org.struts2.Upload.FileDownloadAction">
<param name="inputPath">\files\abc.jpg</param>
<result name="success" type="stream">
<param name="contentType">image/jpg</param>
<param name="inputName">targetFile</param>
<param name="contentDisposition">filename="abc.jpg"</param>
<param name="bufferSize">4096</param>
</result>
</action>
</package>
(IV)这是我的Action:
package org.struts2.Upload;import java.io.InputStream;
import org.apache.struts2.ServletActionContext;
import com.opensymphony.xwork2.ActionSupport;public class FileDownloadAction extends ActionSupport{
private String inputPath; public void setInputPath(String value) {
inputPath = value;
}
public InputStream getTargetFile() throws Exception {
return ServletActionContext.getServletContext().getResourceAsStream(inputPath);
}
}
(V)HTML中的链接:
<h3>文件下载</h3>
<ul>
<li><a href="download.action">点此下载</a></li>
</ul>(VI)web.xml是没有问题的。
2010-3-29 16:11:26 com.opensymphony.xwork2.util.logging.commons.CommonsLogger error
严重: Can not find a java.io.InputStream with the name [targetFile] in the invocation stack. Check the <param name="inputName"> tag specified for this action.
(II)这是浏览器报的exception:
Struts has detected an unhandled exception: Messages: Can not find a java.io.InputStream with the name [targetFile] in the invocation stack. Check the tag specified for this action.
File: org/apache/struts2/dispatcher/StreamResult.java
Line number: 237
(III)这是我的struts.xml
<package name="download" extends="struts-default">
<action name="download" class="org.struts2.Upload.FileDownloadAction">
<param name="inputPath">\files\abc.jpg</param>
<result name="success" type="stream">
<param name="contentType">image/jpg</param>
<param name="inputName">targetFile</param>
<param name="contentDisposition">filename="abc.jpg"</param>
<param name="bufferSize">4096</param>
</result>
</action>
</package>
(IV)这是我的Action:
package org.struts2.Upload;import java.io.InputStream;
import org.apache.struts2.ServletActionContext;
import com.opensymphony.xwork2.ActionSupport;public class FileDownloadAction extends ActionSupport{
private String inputPath; public void setInputPath(String value) {
inputPath = value;
}
public InputStream getTargetFile() throws Exception {
return ServletActionContext.getServletContext().getResourceAsStream(inputPath);
}
}
(V)HTML中的链接:
<h3>文件下载</h3>
<ul>
<li><a href="download.action">点此下载</a></li>
</ul>(VI)web.xml是没有问题的。
你在页面传过来的参数
需要Action的类中有对应匹配类型并且名字完全一致的参数与之对应的
并且需要set和get方法
如果你没有
你点击页面的那些东西
根本没用的你的ActionSupport类看起来好奇怪啊
TargetFile在Action中有get方法:
public InputStream getTargetFile() throws Exception {
return ServletActionContext.getServletContext().getResourceAsStream(inputPath);
}
我在一本书中看到TargetFile要写成targetFile即首字母小写。
struts2的文档中说inputName的默认值是inputStream
那这样写<param name="inputPath">\files\abc.jpg</param>路径好像没问题吧。
要在tomcat的目录下建立一个文件夹名叫files。