struts2下载DOC时出错提示:java.lang.ClassCastException: java.io.ByteArrayInputStream

如题:项目用S2SH框时,在ACTION里读取DOC文件,struts.xml配置文件代码如下:
 <package name="test" extends="struts-default" namespace="/test">
	    <default-action-ref name="download"/>
	  	<action name="getDocFile" class="downloadAction" method="getDownLoadFile">
	  	<param name="filePath">/res/test.doc</param>
	  	<result name="success" type="stream">
	  	<param name="contentType">application/octet-stream;charset=ISO8859-1</param>
	  	<param name="ipnutName">downLoadFile</param>
	  	<param name="contentDisposition">attachment;filename="test.doc"</param>
	  	<param name="bufferSize">4096</param>
	  	</result>
	  	</action>
	 
	 </package>

ACTION的代码如下:

@Controller("downloadAction")
@Scope("prototype")
public class DownLoadAction implements Action {
	
	private InputStream inputStream;
	private String filePath;
	
	public InputStream getDownLoadFile(){
		System.out.println(filePath);

		return ServletActionContext.getServletContext().getResourceAsStream(filePath);
	}

	public InputStream getInputStream() {
		return inputStream;
	}

	public void setInputStream(InputStream inputStream) {
		this.inputStream = inputStream;
	}

	public String getFilePath() {
		return filePath;
	}

	public void setFilePath(String filePath) {
		this.filePath = filePath;
	}



当在页面点击下载时会出现如下提示:
description The server encountered an internal error () that prevented it from fulfilling this request.

exception 

java.lang.ClassCastException: java.io.ByteArrayInputStream
	com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:451)
	com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:280)
	com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:243)
	com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:165)
	com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
	com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
	com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:252)
	org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor
…………………………


我自己也郁闷一天了,这个功能就是做不出来,而下载为txt文件时就没有问题,请帮忙解决一下,急啊!!!!!


=================================================================================

谢谢各位,问题已经解决了,换了其他的方法来解决项目需要了:)



你可能感兴趣的:(java,apache,xml,struts,prototype)