• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Servlet Communication

 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello All,

I have one servlet in which i have code to return to forward the response to the corresponding JSP's

I had to create another servlet and get some logic there and in its service method i have made some out.println statement to be printed on the jsp

so from the first servlet i have to call the second one and display the output from the second onto a jsp, please help me with this

i am not able to do it because i am trying to use the getservlet method to get the servlet but that method is deprecated so i am getting a null here

thanks in advance
 
Sheriff
Posts: 67752
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It actually sounds like you need some refactoring, but...

Why are you trying to use getServlet()? Why not just forward to the servlet?
 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
use RequestDisptcher object to servlet/servlet or servlet/jsp communication. Use include/forward method based on your requirement
 
Chinni Bujji
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes i do need some refactoring but i am not able to do it
i am getting confused

basically in second servlet i have init method and service methods and the service method gives me the jsp code
so i am not able to understand how to place that code in the first serlvet

please help me on this

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Chinni,

If its regarding what code to use in your first servlet to communicate to the second that your are having question, you can use either of the below:



Or you can use ServletContext's getRequestDispatcher(String resource) to do the same.



I was able to see a good link which explains this pretty simpler and clearer way. Click here to access it.
Let me know if it helps
 
If you send is by car it's a shipment, but if by ship it's cargo. This tiny ad told me:
New web page for Paul's Rocket Mass Heaters movies
https://coderanch.com/t/785239/web-page-Paul-Rocket-Mass
reply
    Bookmark Topic Watch Topic
  • New Topic