• Post Reply Bookmark Topic Watch Topic
  • New Topic

Extending a class in JSP

 
Sindu Ram
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have the following requirement - which most web apps would have. Once a user has logged in, I set a session variable to indicate that the user has logged in. On each JSP page, I then check this variable to ensure that the user has indeed logged in and that the session is valid.
In previous projects, I was achieving this by putting the code to check for this variable in a jsp file and including this in all the other jsp pages. However, I received a suggestion recently from a colleague who suggested that I instead write a base class that would extend from HttpServlet and have all my jsp pages extend this class.
Would like inputs on which would be a better approach and whether there are any issues in extending all JSPs from a base class.
Thanks in advance,
Sindu
 
Idly Vada
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think it is better to put all your login validations in a servlet that extends HttpServlet. Simply use this servlet to perform login validations from your JSP. Use JSPs for presentation intensive tasks. For controlling purposes go for servlets.
I don't see any reason why your JSP should extend the login validation servlet.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65530
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the JSP forum, Sindu!
You'll find this forum a great place to seek help on JSP pages, and there aren't many rules you'll have to worry about, but one is that proper names are required. Please take a look at the JavaRanch Naming Policy and change your display name to match it.
Thanks!
bear
JSP Fourm Bartender
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!