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

Discussions

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)

    hi
     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.

    http://www.servlets.com/resources/com.oreilly.servlet/index.html

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

    Sally
  4. hi friend

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

      http://216.127.78.46/resources/com.oreilly.servlet/

    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:

    http://developer.java.sun.com/developer/onlineTraining/Programming/JDCBook/aucserv.html

    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") )
            break;
        }

        // Read the XML and skip the crap after XML

        while ( line != null )
        {
          buffer.append(line);
          if ( line.startsWith("</myXML") )
            break;
          line = br.readLine();
        }

        return buffer.toString();
      }