David Mossakowski <[EMAIL PROTECTED]> wrote:
>I'm writing a fairly straightforward application but already I have many
>conditions for each request. There are two types of searches indicated
>by searchType parameter, there are different results set based on other
>parameters, there is option to log in and others.
>
>The bottom line is that the logic that goes into figuring out what
>should happen based on what values are null and what values are
>something meaningfull is becoming too complex and unmaintainable.
>
>Question: What are my options here? For now I tried to get the
>parameters and then .include. response of other servlets based on these
>parameters. So basically each form is submitted to the same servlet but
>I sometimes include other servlet or forward request somewhere too.
>
>How can this be done in an organized way? Is it better to have seperate
>servlets for each simple task?
It is probably better to have separate servlets for each simple task, though
having lots of servlets can be a pain to administer. Here is one way to keep
the administration headaches down, although it is somewhat more expensive in
terms of processor time and therefore might not meet your needs:
Write just one servlet; let's call it "bob". It calls view methods based in
its extra path info. For example,
/servlet/bob/Login
would use reflection to find class "com.yourcompany.servlet.Login" and call
a static method called "doView( HttpRequest, HttpResponse )". "doView()"
would do get input from the HttpRequest, do its processing, and write to
HttpResponse, just like a servlet would. If you were going to have a lot of
view classes, you could handle package names too:
/servlet/bob/search/MuffinSearch
would use reflection to call method
"com.yourcompany.servlet.search.MuffinSearch.doView( request, response )".
One problem with this approach is that some (all?) servers will dynamically
reload classes that extend from HttpServlet if they are changed, but they
won't (or at least mine won't) dynamically reload other classes (such as the
view classes I just wrote about), so you'd have to restart the server when
you made changes.
Erik
___________________________________________________________________________
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