• 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 can I do in Object-Oriented way in Servlet?

 
Ranch Hand
Posts: 139
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 193
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
reply
    Bookmark Topic Watch Topic
  • New Topic