Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How can I do in Object-Oriented way in Servlet?

 
Ken Shamrock
Ranch Hand
Posts: 139
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have two kind of users: user and staff,
I made seperated Servelt for both,
user.java for user login, create user session, login, registration, etc.
staff.java for staff login, create staff session, login but no registration
If in java, staff.java can extends user, but in Servlet, I can't, as it have extends HTTPservlet already. So how can I do in OO way?
 
Graeme Brown
Ranch Hand
Posts: 193
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have a single login servlet.
User inputs user login credentials.(username,password?)
if (valid credentials sent)
Set status of user to logged in
if (credentials are for a user)
create user session (bean)
forward to registration servlet/jsp
else if (credentials are for staff)
create staff session (bean)
forward to ...
You should investigate the MVC design pattern, you will find it useful not only with servlets but in other areas of your java programming.
[ February 07, 2002: Message edited by: Graeme Brown ]
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13048
6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
General advice - don't try to do everything in the servlet class, make helper classes and use them. If the servlet class code is bigger than anything else in your project, it is time to refactor! If your doGet or doPost method is huge, it is time to refactor.
Don't be shy about passing request and response objects to helper classes.
JavaBeans style helper classes are your friends because if you need to write JSP they move right in.
Bill
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic