• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Connect Two Servlet

 
Jigeshs Shahs
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to communicate between 2 Servlet.any way through which I can do it.

For e.g.Suppose I have a Html form and I extract some data from this form with the help of the sevlet(I am able to do it).All I want ot know out of this data I want to pass some of the data to another servlet.
So I want to know whether this is possible.
If possible how?

In short i want to know how two servlets can communicate
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65229
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why?

Answering that question may help answer the question.
 
Apoorv Srivastava
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes indeed you can pass form parameters from one servlet to the other using RequestDispatcher.
One of the below out of 1/2/3 can be used
1)RequestDispatcher view=request.getRequestDispatcher("jsp_name.jsp");
2)RequestDispatcher view=request.getRequestDispatcher("/jsp_name.jsp");
3)RequestDispatcher view=getServletContext().getRequestDispatcher("/jsp_name.jsp");
and then
view.forward(request,response);
This forwards request and response to the other element of the web-app.
You can also use application scoped dynamic attributes to store form data in them so that every resource in the web-app can use it..

 
sakthi vadivel
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes indeed you can pass form parameters from one servlet to the other using RequestDispatcher.
One of the below out of 1/2/3 can be used
1)RequestDispatcher view=request.getRequestDispatcher("jsp_name.jsp");
2)RequestDispatcher view=request.getRequestDispatcher("/jsp_name.jsp");
3)RequestDispatcher view=getServletContext().getRequestDispatcher("/jsp_name.jsp");
and then
view.forward(request,response);
This forwards request and response to the other element of the web-app.
You can also use application scoped dynamic attributes to store form data in them so that every resource in the web-app can use it..


while you do forward add request parameters.

or you can set session attribute

Or else you can go for context attribute

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic