Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Servlets and the fly likes Can some please explain this? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Can some please explain this?" Watch "Can some please explain this?" New topic
Author

Can some please explain this?

A Harry
Ranch Hand

Joined: Jan 23, 2002
Posts: 124
Just testing the effects of throwing a ServletException from my doPost method to make sure my error.jsp page handle it -

public class UploadServlet extends HttpServlet
{
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException
{
throw new ServletException("test exception");
}
}

this works & my error page is called BUT the exception stack trace is output to the console regardless - surely if I'm handling the exception this shouldn't happen? - how can I suppress it's output? or am I doing something wrong!

thanks

harry
Mahmoud Hadad
Ranch Hand

Joined: Jan 09, 2006
Posts: 67
have you defined an erroe-page header in your deployment descriptor?
A Harry
Ranch Hand

Joined: Jan 23, 2002
Posts: 124
Hi Mahmoud, I have this in my web.xml file

<error-page>
<exception-type>java.lang.Exception</exception-type>
<location>/error.jsp</location>
</error-page>
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

this works & my error page is called BUT the exception stack trace is output to the console regardless

So it is output to the console, is this a problem?
You're not actaully managing the Exception, you're allowing the container to manage it, and this is what it is doing. If you don't want it in the console, catch the exception and redirect to the error page instead.

Dave
A Harry
Ranch Hand

Joined: Jan 23, 2002
Posts: 124
Thanks for that David, just one question though, "redirect to the error page instead", I assume you mean using response.sendRedirect("error.jsp")?, won't that lose the exception object from which I want to tell what sort of exception occured? (sorry for being a bit thick!)

thanks

harry
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60774
    
  65

Yes, it would. If you want to preserve the request environment you would forward rather than redirect.

But, what's your issue with letting the container do it's own thing? Why do you not want the errors to appear on the console? That's a very desirable thing in my view.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
A Harry
Ranch Hand

Joined: Jan 23, 2002
Posts: 124
The situation is this -

I have a struts app which I have to provide a file upload facility. Because I have my Form using enctype="multipart/form-data" the Struts framework generates this warning -

"One of the getParameter family of methods called after reading from the
ServletInputStream. Not merging post parameters"

This is because I beleive Struts use's getParameter() in it's standard framework. This however has no adverse effect in my app but obviously I would prefer it not to happen. So hence trying to do the upload using a Servlet cutting out Struts. This works fine except for the error handling!

From my session facade I throw an Exception when there is a problem with the uploaded file i.e InvalidZIPFileException extends Exception. It's this InvalidZIPFileException that I want to pass to my error page & display a custom error message.

I hope this makes some sense?

harry
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Can some please explain this?
 
Similar Threads
Forwarding exception from servlet to JSP
Customised Error page in case of exception in application server
HELP: doPost without throw
servlet/jsp exception handling question
servlet/jsp exception handling question