I get to that page below fine. It's an intranet site behind a
firewall so I dont' think you'll be able to get there.
I'm suspecting the problem has something to do possibly with sending
multipart/form-data in the request object? Does this possibly have to
be handled differently in order to enable a redirect in a servlet?
The reason I suspsect this is part of the problem is I stripped out
all the code and just put a simple redirect in the try block and when
I call the servlet it still will not redict. However if I go to the
form page that calls this servlet and I remove the <form
ENCTYPE="multipart/form-data" action=...>, the servlet will redirect
fine. So possibly when sending multipart/form-data the servlet is
required to handle it differently???
Is anyone familiar with this problem? (By the way the code works fine
if I jack up the file size allowed and make sure the file being
uploaded is below that size. It's set to 1Meg now for debugging. I'd
like to be able to send a redirect or out.prints that are cleaner if
the user happens to upload a file that is too large. Right now I am
unable to do this).
Thanks again for any help.
On 8 Mar 2001, at 17:07, Nishit Trivedi wrote:
> try connecting to following page thru your favourite browser...
>
> http://www.insidectm.com/ctmig/mainsite/faq.html
>
> At least i couldn't connect to that page..It says "Page not found"
> both in IE and netscape...same error as you got...
>
> If this still doesn't solve your problem then create one test html
> page (in same directory) and redirect request to that page...
>
> Nishit
>
> -----Original Message-----
> From: Rick Reumann [mailto:[EMAIL PROTECTED]]
> Sent: Thursday, March 08, 2001 4:49 PM
> To: [EMAIL PROTECTED]
> Subject: why redirect in this catch not working?
>
>
> This is puzzling me. This happens be in a servlet that I modified. In
> the code if a user tries to upload a file that is larger than the max
> file size that is set in the servlet it throws an IO Exception. The
> problem is in the catch I can't seem to redirect the user to a new
> page (or print to the screen for that matter). Regardless of whether I
> have the redirect in the catch or not, the user is simply returned
> with your typical browser "Page not found" error. This is puzzling me
> because the System.out.println is being reached in the catch, yet I
> can do a redirect in the catch nor print to the screen, etc. Any ideas
> what is causing the page to display the "page not found" error and not
> handle a redirect in the catch block at the end??? Thank you for any
> help. Rick
>
> 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");
> out.println("Parser Upload Servlet");
>
>
> try {
> //rick added or moved around
> String name = null;
> String uploadDir = null;
> String SaveAsFilename = null;
> File dir = null;
> //:~ end rick added
>
> FilePart filePart = null;
>
> MultipartParser mp = new
> MultipartParser(request,
> 1*1024*1024); // 1MB
> Part part;
> while ((part = mp.readNextPart()) != null) {
> name = part.getName();
> if (part.isParam()) {
> // it's a parameter part
> ParamPart paramPart = (ParamPart)
> part;
> String value =
> paramPart.getStringValue();
> out.println("param; name=" + name +
> ", value=" + value);
>
> //rick added
> if ( name.equals("uploadDir") )
> uploadDir = value; if (
> name.equals("SaveAsFilename") )
> SaveAsFilename = value; //:~end
> rick added
>
> }
> else if (part.isFile()) {
> // it's a file part
> filePart = (FilePart) part;
> }
> }
>
> //rick added
> String pathAndFile = uploadDir +
> SaveAsFilename;
> System.out.println("ParserUpload. pathAndfile
> =
> "+pathAndFile);
> dir = new File(pathAndFile);
> //:~ end rick added
>
> String fileName = filePart.getFileName(); if
> (fileName != null) {
> // the part actually contained a file
> long size = filePart.writeTo(dir);
> out.println("file; name=" + name + ";
> filename=" + fileName +
> ", content type=" +
> filePart.getContentType() + " size=" + size);
> }
> else {
> // the field did not contain a file
> out.println("file; name=" + name + ";
> EMPTY");
> }
>
> out.flush();
>
> }
>
> catch (IOException lEx) {
> System.out.println("PaserUploadServlet.
> catchIO
> Exception : "+lEx);
>
> response.sendRedirect("http://www.insidectm.com/ctmig/mainsite/faq.htm
> l");
> return;
> //this.getServletContext().log(lEx, "error
> reading
> or saving file");
> }
> }
> }
>
> ======================================================================
> ===== 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
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