File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes How can I do in Object-Oriented way in Servlet? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "How can I do in Object-Oriented way in Servlet?" Watch "How can I do in Object-Oriented way in Servlet?" New topic

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

Ken Shamrock
Ranch Hand

Joined: Jan 23, 2002
Posts: 139
I have two kind of users: user and staff,
I made seperated Servelt for both, for user login, create user session, login, registration, etc. for staff login, create staff session, login but no registration
If in java, can extends user, but in Servlet, I can't, as it have extends HTTPservlet already. So how can I do in OO way?

Thanks everyone who helped me
Graeme Brown
Ranch Hand

Joined: Oct 13, 2000
Posts: 193
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

Joined: Mar 22, 2000
Posts: 13036
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.
I agree. Here's the link:
subject: How can I do in Object-Oriented way in Servlet?
It's not a secret anymore!