COS文件上传组件在Struts1.X环境下的问题[SOS]

[SOS]紧急救援
问题是这样的:
我使用文件上传组件COS进行文件的上传操作,按照COS的例子,我也成功的做了一个Demo,但这个Demo是这样的.有两个JSP文件:
a.jsp(用于生成上传界面)
upload.jsp(内嵌了javaCode实现文件上传操作)
我想对他进行点改进,就是说:我实现文件上传的代码我想写在StrutsAction中,而不是嵌在一个JSP里面.具体我是怎么写的,请看下面的代码:
a.jsp的代码如下:
<!-- 测试集成COS文件上传效果 -->
<%@ page contentType="text/html; charset=GBK"%>
<html>
	<body>
		<form name="form1" method="post" enctype="multipart/form-data"
			action="upload.jsp">
			<input name="file1" type="file"><br>
			<input name="file2" type="file"><br>
			<input name="file3" type="file"><br>
			<input type="submit" name="Submit"  value="上传">
		</form>
	</body>
</html>


upload.jsp的代码如下:
<%@ page contentType="text/html; charset=gb2312" %>
<%@ page import="java.util.Enumeration"%>
<%@ page import="com.oreilly.servlet.MultipartRequest" %>
<%@ page import="java.io.File" %>
<html>
  <head>
  </head>
  <body>
    <%
    String saveDirectory = "c:\\upload";
    //每个文件最大5m,最多3个文件    
    int maxPostSize = 3 * 5 * 1024 * 1024;
    //response的编码为"gb2312",同时采用缺省的文件名冲突解决策略,实现上传   
    MultipartRequest multi = new MultipartRequest(request,saveDirectory, 
        maxPostSize, "gb2312");
    //输出反馈信息   
    Enumeration file = multi.getFileNames();
    while (file.hasMoreElements()) {
    	String name = (String) file.nextElement();
    	File f = multi.getFile(name);
    	if (f != null) {
    		String fileName = multi.getFilesystemName(name);
    		String lastFileName = saveDirectory + "\\" + fileName;
    		out.println("文件已经上传到:" + lastFileName);
    		out.println("<br>");
    		}
    	}
    %>
  </body>
</html>

通过上面的两个JSP文件,我成功的完成了我的上传操作!
但是,我把它移植到Struts的Action中就报错了。请继续往下看:
a-1.jsp的代码如下:
<!-- 测试集成COS文件上传效果 -->
<%@ page contentType="text/html; charset=GBK"%>
<html>
	<body>
		<form name="form1" method="post" enctype="multipart/form-data"
			action="/uploadAction.do">
			<input name="file1" type="file"><br>
			<input name="file2" type="file"><br>
			<input name="file3" type="file"><br>
			<input type="submit" name="Submit"  value="上传">
		</form>
	</body>
</html>


UploadActionForm.java的代码如下:
public class UploadActionForm extends ActionForm {
	private FormFile file1 = null;
	private FormFile file2 = null;
	private FormFile file3 = null;
         ........
         ........//省略


UploadAction的代码如下:
public class UploadAction extends Action {
	/**
	 * @name execute
	 * @title 测试文件上传组件COS集成效果
	 * @param ActionMapping,ActionForm,HttpServletRequest,HttpServletResponse
	 * @return ActionForward
	 * @description
	 */
	public ActionForward execute(ActionMapping mapping, ActionForm form,
		HttpServletRequest request, HttpServletResponse response)
			throws Exception {
	    String saveDirectory = "c:\\upload";
	    //每个文件最大5m,最多3个文件    
	    int maxPostSize = 3 * 5 * 1024 * 1024;
	    //response的编码为"gb2312",同时采用缺省的文件名冲突解决策略,实现上传   
	    MultipartRequest multi = new MultipartRequest(request,saveDirectory, 
	        maxPostSize, "gb2312");
	    //输出反馈信息   
	    Enumeration file = multi.getFileNames();
	    while (file.hasMoreElements()) {
	    	String name = (String) file.nextElement();
	    	File f = multi.getFile(name);
	    	if (f != null) {
	    		String fileName = multi.getFilesystemName(name);
	    		String lastFileName = saveDirectory + "\\" + fileName;
			response.getWriter().println("文件被上传到:" + lastFileName);
			response.getWriter().println("<br>");
	    		}
	    	}
		return mapping.findForward("jspView");
	}
}


我请求这个页面的时候,控制台报出如下错误信息:
2007-11-02 01:45:54,750 DEBUG [http-8082-Processor23] - Executing org.apache.struts.chain.commands.servlet.ExceptionHandler
2007-11-02 01:45:54,750 DEBUG [http-8082-Processor23] - See if actionConfig ActionConfig[cancellable=falsepath=/test_4Actionvalidate=false,input=jspView,name=test_4ActionForm,scope=request,type=com.eredlab.eredcip.test.web.action.Test_4Action has an exceptionConfig for java.io.IOException
2007-11-02 01:45:54,750 DEBUG [http-8082-Processor23] - findException: look locally for java.io.IOException
2007-11-02 01:45:54,750 DEBUG [http-8082-Processor23] - findException: look globally for java.io.IOException
2007-11-02 01:45:54,750 DEBUG [http-8082-Processor23] - findException: look locally for java.lang.Exception
2007-11-02 01:45:54,750 DEBUG [http-8082-Processor23] - findException: look globally for java.lang.Exception
2007-11-02 01:45:54,750 DEBUG [http-8082-Processor23] - findException: look locally for java.lang.Throwable
2007-11-02 01:45:54,750 DEBUG [http-8082-Processor23] - findException: look globally for java.lang.Throwable
2007-11-02 01:45:54,750 DEBUG [http-8082-Processor23] - findException: look locally for java.lang.Object
2007-11-02 01:45:54,750 DEBUG [http-8082-Processor23] - findException: look globally for java.lang.Object
2007-11-02 01:45:54,750  WARN [http-8082-Processor23] - Unhandled exception
java.io.IOException: Posted content type isn't multipart/form-data
	at com.oreilly.servlet.multipart.MultipartParser.<init>(MultipartParser.java:166)
	at com.oreilly.servlet.MultipartRequest.<init>(MultipartRequest.java:222)
	at com.oreilly.servlet.MultipartRequest.<init>(MultipartRequest.java:173)
	at com.eredlab.eredcip.test.web.action.Test_4Action.execute(Test_4Action.java:39)
	at org.apache.struts.chain.commands.servlet.ExecuteAction.execute(ExecuteAction.java:53)
	at org.apache.struts.chain.commands.AbstractExecuteAction.execute(AbstractExecuteAction.java:64)
	at org.apache.struts.chain.commands.ActionCommandBase.execute(ActionCommandBase.java:48)


不知如何解决,请指教,
鞠躬!

你可能感兴趣的:(java,apache,jsp,struts,servlet)