File Upload In Jsp

 
More
 
More
 5th Jun 2007 12:38:13 AM

sram_2004  
 
 file upload in jsp
 
hi,

i want to upload a file in jsp.
i have many doubt abt it. so,plz give some example program about that file upload in JSP.

Thanks for advance
 
More
 
  # 15th Jun 2007 07:28:17 AM

vijayspace  
 
 
..........
<form action="upload.jsp"
  method="post" enctype="multipart/form-data">

  Select a file: 
  <input type="file" name="first" />
  
  <br />
  <input type="submit" name="button" value="upload" />
  
</form>
..........

The page processing request with file encoded:

<%@page contentType="text/html;"%>

<%@page import="java.util.Hashtable"%>
<%@page import="javazoom.upload.MultipartFormDataRequest" %>

...........

<%
  try {
    // decode source request:
    MultipartFormDataRequest data = 
       new MultipartFormDataRequest(request);

    // get the files uploaded:
    Hashtable files = data.getFiles();
    
    if (! files.isEmpty()) {
      // do something with collection of files uploaded;
      ........
    else {
      throw new IllegalStateException("No files supplied");
    }
  catch (RuntimeException error) {

    // set error flag in session:
    request.getSession().setAttribute("error", error);

    // throw its further to print in error-page:
    throw error;
  }
%>
 
More