Most books on servlets talk about servlet chaining and
servlet engines have their unique implementation.
There's another idea one might want to consider:
Make your servlets very dumb and delegate all your
business logic/processing to appropriate controllers.
So you might have several "Save" controllers and only
one "CaptureInfo" controller. With this in hand you
can have ServletA delegate work to "SaveA" and
"CaptureInfo" controllers, ServletB delegate work to
"SaveB" and "CaptureInfo" controllers.
Tinou Thinh Bao
web www.tinou.com
email [EMAIL PROTECTED]
page www.tinou.com/sms.html
calendar www.tinou.com:78/?calTBao
fax 877.209.7378
--- "Hunter, Roger" <[EMAIL PROTECTED]> wrote:
> I need some help calling a servlet from a servlet.
> In several places throughout the system we need to
> capture common info from
> the user
> when they do a certain activity. For example there
> are many places that have
> a 'save' button.
> The save code in each servlet is appropriate only
> for that servlet, but we
> find we need to capture
> some common info from the user each time a 'save'
> button is pressed.
>
>
> My thought are to write a method that would capture
> this information and
> return the captured data. The call to this method
> could easily be put in the
> save logic in each servlet. The common information
> would be captured using a
> servlet. That servlet would need to interact with
> the user any number of
> times until any required data is entered. So now I
> call a helper method from
> the save logic which then calls the common servlet.
> When the helper method
> ends it of course returns to the original servlet.
>
> I need the common servlet to go into a normal
> servlet 'cycle' where I can
> check the data passed to from the user and decide
> whether to cycle back to
> interact with the user to enter more data or to
> return to where it was
> called from.
>
> The problem I have is that the common servlet runs
> straight through and
> returns to the method that called it. It does send
> out its HTML to the
> browser but it then just runs on. By the time the
> user is looking at the
> screen from the common servlet execution has
> returned all the way back to
> the originating servlet. If I add the ACTION
> attribute of the FORM statement
> with the URL of the common servlet the servlet will
> of course call itself
> and cycle. It then of course forgets the method that
> called it and cannot
> return to it.
>
>
> I feel like I am just missing something. Am I just
> barking up the wrong tree
> here? Can anyone give me some ideas on how they
> would accomplish what I need
> to do?
>
>
>
> Below are the two ways I have called the common
> servlet.
>
> 1.) Call getRequestDispatcher and then call the
> include method of the
> RequestDispatcher object. (From
>
http://java.sun.com/docs/books/tutorial/servlets/communication/request-dispa
> tcher.html)
>
>
> 2.) Using Attributes:
>
> Put
> public static String KEY = "ServletName"
> in the called servlet and put
> getServletContext().setAttribute(KEY, this)
> in the init() method of the called servlet.
>
> To call the common servlet I then do:
>
> Object o =
> myServletContext.getAttribute(commonServlet.KEY);
> commonServlet varObject = (commonServlet) o;
> varObject.doAction(request,res);
>
>
> This way seems a bit messy. The common servlet must
> be called once before it
> can be used to run init().
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> Roger Hunter
> Centers for Disease Control and Prevention
> NCID/SRP/IRM
> (404) 639-4645
> [EMAIL PROTECTED]
>
>
===========================================================================
> To unsubscribe, send email to [EMAIL PROTECTED]
> and include in the body
> of the message "signoff EJB-INTEREST". For general
> help, send email to
> [EMAIL PROTECTED] and include in the body of the
> message "help".
>
__________________________________________________
Do You Yahoo!?
Get Yahoo! Mail � Free email you can access from anywhere!
http://mail.yahoo.com/
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff EJB-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".