commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Guojun Zhu <shmilyle...@yahoo.com>
Subject [uploadfile]
Date Tue, 08 Aug 2006 05:20:07 GMT
I am using netbean 5.5beta2 with tomcat 5.5.17 for a jsp. 
 
I keep getting error like this
 
HTTP Status 500 -
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling
this request.
exception
org.apache.jasper.JasperException: Exception in JSP: /index.jsp:51
 
48: ServletFileUpload upload = new ServletFileUpload(factory);
49: 
50: // Parse the request
51: List /* FileItem */ items = upload.parseRequest(request);
52: %>
53:   
54: 
 
I have put the common jar file in the web-inf directory of the web subdirectory, where index.jsp
sits.    It complies fine.  The jsp works file without revoking by the form query.  

Here is the file invoke the jsp 

   
 
  <form name="tt" action="index.jsp" method="POST" enctype="multipart/form-data">
      <input type="text" name="text" value="" />
      <input type="file" name="file" value="" />
      <input type="submit" value="submit" name="submit" /></form>
 
 
Here is the jsp code
 
   <%@ page import="jspIn24.OverridingToString"%>
   <%@ page import="org.apache.commons.fileupload.*"%>
     <%@ page import="org.apache.commons.fileupload.servlet.*"%>
     <%@ page import="org.apache.commons.fileupload.disk.*"%>
          <%@ page import="java.util.*"%>
             <%@ page import="java.io.*"%>
     
   <% boolean isMultipart = ServletFileUpload.isMultipartContent(request);%>
   <% if (isMultipart){%>
<%// Create a factory for disk-based file items
FileItemFactory factory = new DiskFileItemFactory();
// Create a new file upload handler
ServletFileUpload upload = new ServletFileUpload(factory);
// Parse the request
List /* FileItem */ items = upload.parseRequest(request);
%>
  
<%// Process the uploaded items
Iterator iter = items.iterator();
while (iter.hasNext()) {
    FileItem item = (FileItem) iter.next();
    if (item.isFormField()) {
        // Process a regular form field
    String name = item.getFieldName();
    String value = item.getString();
   } else {
    String fieldName = item.getFieldName();
    String fileName = item.getName();
    String contentType = item.getContentType();
    boolean isInMemory = item.isInMemory();
long sizeInBytes = item.getSize();%>
Filename:<%=fileName%>
fieldName:<%=fieldName%>
contentType:<%=contentType%>
<%
    File uploadedFile = new File(fileName);
    item.write(uploadedFile);
    }
}
   }   
%>  


Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message