Reputation: 2843
Is it possible to send http post back request by request dispatcher to a servlet in a different project. I tried but
the given url is checked in same project and gives 404 error...
HTTP Status 404 - /FilterI/http:/IP:8080/FilterII/RequestServlet
type Status report
message /FilterI/http:/IP:8080/FilterII/RequestServlet
description The requested resource (/FilterI/http:/10.49.11.197:8080/FilterII/RequestServlet) is not available.
Both the wars are deployed on the same server.I can achieve the same thing by using .sendRedirect() function..However why is it not running with the help of requestdispatcher.
Upvotes: 0
Views: 3169
Reputation: 15446
Yes, using ServletContext API. You can get the servlet context of the other application using ServletContext.getContext("othercontext")
and get request dispatcher of the servlet within that application.
Below is the code explaining how to do this:
ServletContext otherCtx = currentServletContext.getContext("otherContext");
RequestDispatcher dispatcher = otherCtx.getRequestDispatcher("/forwardedPath");
dispatcher.forward(request, response);
Upvotes: 2
Reputation: 691635
The javadoc says:
The pathname specified may be relative, although it cannot extend outside the current servlet context.
(emphasis mine)
So, what you're asking is not possible.
Upvotes: 1