• Post Reply Bookmark Topic Watch Topic
  • New Topic

Servlet to Servlet Communication  RSS feed

 
Jenn Person
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I can make servlets, but I don't know how to pass information back and forth between them. Can anyone lead me to a proper demonstration? By proper, I mean the usual practice as opposed to something weird I might try and make up.

Thank you!!
Jenn
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
pass information back and forth between them


This is too vague to formulate an answer. What is the relationship between the servlets?
 
Jenn Person
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm in university and taking a class on design patterns. For my term project, I want to make a site that will use the Front Controller pattern, and as such as requests come in, this front controller servlet will summon/command/activate other servlets.

Here is a link I found on it: http://www.martinfowler.com/eaaCatalog/frontController.html

I'm a little unsure as to how this front controller works, in terms of interpreting the input from the browser and then communicating with another servlet for processing.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually, the front controller usually does not forward to another servlet, but to a class that follows the Command pattern.

But, when forwarding from servlet to servlet (or from servlet to JSP), scoped variables placed on the request are the most common means to carry data across resources.

You might also find this article interesting.
 
Jenn Person
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok great, thanks Bear. I'll check out the article you recommended.

As for servlet to servlet, I know how to add scoped variables onto the request object. I'm just unsure about how to send them to another servlet. Would I use the RequestDispatcher?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Scoped variables are set using request.setAttribute(). And yes, forwarding is accomplished with a request dispatcher.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!