Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Connect Two Servlet

 
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
 
Marshal
Posts: 67451
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why?

Answering that question may help answer the question.
 
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..

 
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

 
So I left, I came home, and I ate some pie. And then I read this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic