aspose file tools*
The moose likes Servlets and the fly likes Servlet calling another servlet... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Servlet calling another servlet..." Watch "Servlet calling another servlet..." New topic
Author

Servlet calling another servlet...

Jason Kim
Greenhorn

Joined: Apr 13, 2003
Posts: 17
Hi.
Can a servlet load another servlet in different J2EE application ?
If so, could you show me how ?
Code example would be much appreicated.
Thanks.
Ashik Sherfudeen
Greenhorn

Joined: May 09, 2003
Posts: 2
Hi,

I think v can use Request Despatcher Interface for this. Use forward method to load the server which is in another j2ee application.
If this answer is wrong could u explain why it is wrong.


Every thing is possible.
Amol Desai
Ranch Hand

Joined: Jan 29, 2003
Posts: 82
Hi,
You cannot use the forward method of RequestDispatcher interface.
A forward method allows you to redirect only to a resource in the same Web application.
The sendRedirect method, on the other hand, allows you to redirect to any URL.
Simon Brown
sharp shooter, and author
Ranch Hand

Joined: May 10, 2000
Posts: 1913
    
    6
Moving to the Servlets forum...
Jason Kim
Greenhorn

Joined: Apr 13, 2003
Posts: 17
Servlet in different applications within same virtual host can call each other.
ServletContext context = getServletContext('context-root-name');
context.getRequestDispatcher('uri-of-servlet-to-be-called').forward(request,response);
If applications are in different host, one has to use URL connection or sendRedirect ?
Kaustubh Patil
Ranch Hand

Joined: Aug 13, 2001
Posts: 164
I think using a sendRedirect() would be a solution.
forward() may have problems because redirecting to the different resource takes place on the server side in this case where as in the case of sendRedirect() a browser is made to generate a new request to the resource (which could be anything - maybe on a different server).
Pl. correct me if i am wrong or have missed anything.
-Kaustubh.


Kaustubh. Mumbai, India.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Servlet calling another servlet...