how to upload a file using JSP???-urgent!!


Web tier: servlets, JSP, Web frameworks: how to upload a file using JSP???-urgent!!

  1. how to upload a file using JSP???-urgent!! (4 messages)

     this is keithu
    please help with the code for uploading any file on to a server from a remote area through the net .
       thank you
     reply asap

  2. You need to check out the o'rielly multipart request stuff.

  3. Page 107 of the Java Servlet Programming book by O'Reilly to be exact.

  4. hi friend

    go to
    there is a download to have uplading.
  5. Try this link:

    Here's some additional information:

    Wutka's "Using Java Server Pages and Servlets" - p. 233 has an example.

    Also check out the article on Sun's web site:

    The code I actually ended up using was much simpler than Sun's example. I reduced the code to only what I needed and hard-coded some values as well. Using the Multipart class in J2EE may have been a better solution, but I wasn't sure how to use the class properly and hard-coding worked fine for my current situation.

    Note that the request.getParameter("param") function does not work when using multipart form data. Be aware of this if you have additional parameters that you would like to read on the same page that you are using to upload a file.

      // Read the request header line by line until you find the data you're looking for.
      // In my case, I'm looking for an XML tree that begins with "<myXML>" and ends with
      // "</myXML>"
      private String getXMLFromFile(HttpServletRequest request) throws IOException
        BufferedReader br = request.getReader();
        StringBuffer buffer = new StringBuffer(500000);
        String line;

        // Skip the crap in the header

        while ((line = br.readLine()) != null)
          if ( line.startsWith("<myXML") )

        // Read the XML and skip the crap after XML

        while ( line != null )
          if ( line.startsWith("</myXML") )
          line = br.readLine();

        return buffer.toString();