FileDocCategorySizeDatePackage
UploadServlet.javaAPI DocExample1620Tue Feb 10 13:58:08 GMT 2004com.jspservletcookbook

UploadServlet

public class UploadServlet extends HttpServlet

Fields Summary
private String
webTempPath
Constructors Summary
Methods Summary
public voiddoGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)

        
		throw new ServletException("GET method used with " + getClass().getName()+": POST method required.");
    
public voiddoPost(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)

        
       //file limit size of five megabytes
        MultipartRequest mpr = new MultipartRequest(request,webTempPath,
		(5 * 1024 * 1024));
        Enumeration enum = mpr.getFileNames();
        
        response.setContentType("text/html");
        java.io.PrintWriter out = response.getWriter();
    
        out.println("<html>");
        out.println("<head>");
        out.println("<title>Servlet upload</title>");  
        out.println("</head>");
        out.println("<body>");
        
        for (int i = 1; enum.hasMoreElements();i++)
            out.println("The name of uploaded file " + i +" is: " + mpr.getFilesystemName((String) enum.nextElement()) + "<br><br>");
        
        out.println("</body>");
        out.println("</html>");
    
    
public voidinit()

   
webTempPath =   getServletContext().getRealPath("/") + "data";