I'm really stumped here and would love some help....

I have a form that is submitting multipart/form-data. (user browses
and selects a file from his/her drive). The problem is in this
servlet it sumbits to. All I want to do is test for the content
length and if greater than a certain size, cause a redirect. For some
odd reason I can not get this to work. It's as if it being
ENCTYPE="multipart/form-data" causes it to act weird. I'm really
stumped here since I could get into the following condition that
should enable me to do a redirect. (Possibly the problem is
multipart/form-data has to be handled before I can do a redirect?).
The following code is below that is not working (and yes, i've
checked a million times- I do have a valid url that it can redirect
too). When the file is too large that submits to this page I end up
with one of those standard IE page not found errors.

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;

import com.oreilly.servlet.multipart.*;

public class ParserUploadServlet extends HttpServlet {
    private File dir;

    public void init(ServletConfig config) throws ServletException {
        super.init(config);

    }

    public void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        PrintWriter out = response.getWriter();
        response.setContentType("text/plain");

        try
        {
            int maxLength = 2*1024*1024; //2MB
            if (  request.getContentLength() > maxLength )
            {
                // !*** this will not redirect for some reason.
                response.sendRedirect("http://... the error page.com");
                return;
            }
            else
            {
                 //...rest of code does uploading if size isn't too large
                 //do rest of code
                 // ...rest of code does uploading if size isn't too large
            }

            //!!!this below works fine as long as request.getContentLength() < 
maxLength
            response.sendRedirect("http://...the confirmation page ok.com");
                return;
        }
        catch (IOException lEx) {
            System.out.println("PaserUploadServlet. catchIO Exception : "+lEx);
            this.getServletContext().log(lEx, "error reading or saving file");
        }
    }
}

Rick

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets

Reply via email to