Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

session and exception handling in jsp and servlet?

 
Jesus Angeles
Ranch Hand
Posts: 2068
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In creating a new application, what considerations do we do when designing the jsp/servlet application, in relation to session and exceptions?

e.g.
- at each beginning of jsp, always check if session exists? if it is required?
- for exception in servlet or jsp that are not business errors, do we use request parameters and redirect/dispatch into an error jsp?

I have built my first application at work but not sure on these 2 issues of how I want to maintain/control my session, and the exception occurrence.

For exceptions, I simply set error variables into the session and dispatch into a common error jsp. For session, I throw an exception when it is null and it is not expected to be null at that point.
[ October 07, 2006: Message edited by: Bear Bibeault ]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65115
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Avoid having to put goo on each and every JSP page by employing a filter.

Define an error handler in web.xml and write a centralized servlet to handle errors in a consistent fashion.
 
Rahul Bhattacharjee
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Now so many good and trusted MVC frameworks are available that developers do not go for making a application with straight jsp's and servlets. All major MVC frameworks (like struts) provide a global exception handling framework.That will take care of the exceptions from the action classes (in case of struts).
In case you want to make a small application using servlets and jsp's ,you might configure error pages in web. xml for various error codes and exception types so that in case of exception the exception specific page would be displayed.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65115
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Rahul Bhattacharjee:
Now so many good and trusted MVC frameworks are available that developers do not go for making a application with straight jsp's and servlets


I strongly beg to differ.

Please do not speak for all developers. Many experienced developers I know eschew the big and "popular" frameworks.
 
Jesus Angeles
Ranch Hand
Posts: 2068
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Bear Bibeault:
Avoid having to put goo on each and every JSP page by employing a filter.

Define an error handler in web.xml and write a centralized servlet to handle errors in a consistent fashion.


Thanks, I missed that part, using error component in the web xml.

I used redirect to an error page, on all components. If I have time, I will fix the design.
 
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Posts: 4968
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The error pages in the web.xml file are fantastic.

Also, the ability to map specific exceptions to a particular error page is great. You can make your own exceptions, and then map them to specific error pages.

Filters are best to use for tracking sessions, and not only sessions, but that certain objects are inside of the session.

When developing applicatoins, I usually put together a state transition table, and try to isolate a maximum of five potential state transitions. I then create filters that identify whether a person 'should' be in a particular state, and apply those to the appropriate Servlet and JSPs.

State management should never be taken lightly.

-Cameron McKenzie
 
Jaikiran Pai
Marshal
Pie
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When developing applicatoins, I usually put together a state transition table, and try to isolate a maximum of five potential state transitions. I then create filters that identify whether a person 'should' be in a particular state, and apply those to the appropriate Servlet and JSPs.

State management should never be taken lightly.


Was overhearing the converstaion going on in this thread. I would be interested in knowing what state management and state transition is. Can you please provide a simple example as to what state management is?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic