i think this question came up several times. there's no 'right' answer to
this.

the main pros and cons are pretty obvious:

> a) one servlet for every html page that posts
- (too) many different servlets, which might be harder do manage

> b) one sevlet that handles the posts for several different
- might end up in one (too) big servlet, which might get hard to manage as
well

i guess the optimal solution would be a mixture between both approaches.

another option is to write one main dispatcher servlet, that determines from
the url/pathinfo/querystring where to dispatch to. the actual handling is
then done by a different class.

i for example use a dispatcher servlet that uses the pathinfo to determine
the handling class. this class is then instantiated using
'class.forName(className).newInstance()'.

my handling classes all are subclasses of a main handler class. the main
handler class has a method called handleRequest() that calls several methods
within itself to determine the contentType and then print out the content.
each of those messages will be overwriten by the actual handler class.

so, to create a new handler i extend my main handler class and for example
only overwrite the getContent() method to print out the appropriate html
code.

meaning: no need to register anything or deal with too many methods etc.


but this is just one method to use. there are several other approaches and
frameworks out there that take some of the complexity out of it.

hope that helps (and doesn't confuse too much),
- martin


/ martin gloeckle / senior software engineer /
[EMAIL PROTECTED] /
/ think new ideas, san francisco / http://www.thinkinc.com /
/ san francisco - new york - los angeles - boston - atlanta - seattle -
london - sofia /


> -----Original Message-----
> From: Andrew Psaltis [mailto:[EMAIL PROTECTED]]
> Sent: Friday, May 28, 1999 5:29 AM
> To: [EMAIL PROTECTED]
> Subject: Servlet Design
>
>
> Dear gurus;
> Is there 'best practice' when it comes to designing servlets. More
> specifically is it more common to have
> a) one servlet for every html page that posts
>         or
> b) one sevlet that handles the posts for several different
> (but logically
> grouped) html pages??
>
> Any suggestions on pros and cons and expeirences you may have
> run into would
> be great.
>
> Thanks in advance.
> Andrew Psaltis
>
> ______________________________________________________________
> _____________
> To unsubscribe, send email to [EMAIL PROTECTED] and
> include in the body
> of the message "signoff SERVLET-INTEREST".
>
> Archives: http://archives.java.sun.com/archives/servlet-interest.html
> Resources:
http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to