• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Can some please explain this?

 
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
have you defined an erroe-page header in your deployment descriptor?
 
A Harry
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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>
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 124
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 67754
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
A Harry
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic