• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to generate HTTP 4xx errors from within the application ?

 
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear,
I need for my application to authenticate users.
To make thing smooth in the handling of errors & exceptions I would like to generate a HTTP 403 error (forbidden) when the user attempts to access a forbidden page.
I think that approache is more sensible than having an entry for security exception classes but also for HTTP 403.
Another related question is to know if there is a possibility to handle HTTP 4xx errors in ranges. All 4xx should be send to the DefaultErrorPage.jsp while the 404 & 403 would have specific handlings.
Kind regards,
Thomas,

Thomas,
 
Ranch Hand
Posts: 251
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You could manually send an error with the response object, check here:
http://java.sun.com/products/servlet/2.3/javadoc/javax/servlet/http/HttpServletResponse.html
As far as making some errors hit a certain page, you'd have to check your webserver docs for that.
 
Ranch Hand
Posts: 374
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As noted, you can use the response object to set a status.
Also, you should be able to configure your error pages in your web.xml file so that it redirects to different pages based on the error codes. The catch is that this is per-application, not per application server.
 
Thomas Smets
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Tx for the Servlet reference...
I haven't done many of those in my life
No idea on how to simplify these


<!-- What follows is the handling of the HTTP-errors -->
<!-- Curently defined errors are -->
<!-- 400 : Bad Request -->
<!-- 401 : Unauthorized -->
<!-- 402 : Payment Required -->
<!-- 403 : Forbidden -->
<!-- 404 : Not Found -->
<!-- 405 : Method Not Allowed -->
<!-- 406 : Not Acceptable -->
<!-- 407 : Proxy Authentication Required -->
<!-- 408 : Request Timeout -->
<!-- 409 : Conflict -->
<!-- 410 : Gone -->
<!-- 411 : Length Required -->
<!-- 412 : Precondition Failed -->
<!-- 413 : Request Entity Too Large -->
<!-- 414 : Request-URI Too Long -->
<!-- 415 : Unsupported Media Type -->
<!-- 416 : Requested Range Not Satisfiable -->
<!-- 417 : Expectation Failed -->
<error-page>
<error-code>401</error-code>
<location>error/Unauthorized.jsp</location>
</error-page>
<error-page>
<error-code>403</error-code>
<location>error/Forbidden.jsp</location>
</error-page>
<error-page>
<error-code>404</error-code>
<location>error/NotFound.jsp</location>
</error-page>
...


into something where we don't have to have ONE entry per Exception type but where all 400's are dealed with the 4xx.jsp while only the 404 is dealed with a special JSP, say for instance.
I have now everything fine with the
How can I get the Message back in the response ?
Tx,
Thomas,
[ March 20, 2003: Message edited by: Thomas SMETS ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic