• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Servlet Communication

 
Chinni Bujji
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • 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
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64715
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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?
 
sujith Acharya
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • 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
  • 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

 
Praveen Rajendran
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic