wood burning stoves*
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


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Servlet Communication" Watch "Servlet Communication" New topic
Author

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
Marshal

Joined: Jan 10, 2002
Posts: 61105
    
  66

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] [Bear's FrontMan] [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
Greenhorn

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,
Praveen
 
 
subject: Servlet Communication