File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Servlet Communication Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Servlet Communication" Watch "Servlet Communication" New topic

Servlet Communication

Chinni Bujji
Ranch Hand

Joined: Jan 31, 2007
Posts: 60
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

Joined: Jan 10, 2002
Posts: 63866

It actually sounds like you need some refactoring, but...

Why are you trying to use getServlet()? Why not just forward to the servlet?

[Asking smart questions] [About Bear] [Books by Bear]
sujith Acharya
Ranch Hand

Joined: Dec 25, 2006
Posts: 60
use RequestDisptcher object to servlet/servlet or servlet/jsp communication. Use include/forward method based on your requirement
Chinni Bujji
Ranch Hand

Joined: Jan 31, 2007
Posts: 60
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

Joined: Dec 25, 2009
Posts: 21
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

Thanks & Regards,
I agree. Here's the link:
subject: Servlet Communication
It's not a secret anymore!