And this is the servlet handling the multipart/form data request. Don't forget to define a servlet 
mapping in the web.xml file. 
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.sql.*;
public class UploadExample extends HttpServlet
{
public void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
// Get the content type and the content length
String contentType = req.getContentType();
int contentLength = req.getContentLength();
// Get the servlet input stream
ServletInputStream in = req.getInputStream();
// Perform the multipart request. This stores the file to the specified
// directory, and generates a hashtable containing all the parameters
// that are submitted with the form.
// The paramters can be accessed with the getURLParameter(String) method.
MultipartRequest multipartRequest =
new MultipartRequest(contentType,contentLength,in,"/uploadDir");
// read form paramters
String name = multipartRequest.getURLParameter("Name");
// get the file
File file=multipartRequest.getFile("File");
// Get print writer
PrintWriter out = res.getWriter();
// Print out a table of all items read
out.println(multipartRequest.getHtmlTable());
out.close();
}
}
78 




Java Web Hosting Application Development Using Java Technologies Hosting




 
TotalRoute.net Business web hosting division of Vision Web Hosting Inc. All rights reserved.