3 Replies Latest reply: Feb 13, 2013 5:48 AM by ramp RSS

    RequestDispatch.forward to another context

    990719
      Hi,

      I have one servlet running with following URL.

      http://www.abc.com/abc/xyz/get?file=kvjdjfkj3w3sdlkfjsf3233

      where abc is the application context root and /xyz/get is the servlet url pattern.

      Now I want to do the Request Dispatch forward from this servlet to the different servlet which in not running on the same context root.
      i.e. I want to do the forward to /proxy/aaa/secondServlet

      My new forward URL should not contains the old context root and internal forward url should be look like

      http://www.abc.com/proxy/aaa/secondServlet

      Here domain is same.

      Please help me with the how i can achieve this use RequestDispatcher forward.

      Thanks in advance
        • 1. Re: RequestDispatch.forward to another context
          ramp
          Using a Request Dispatcher of the servlet context allows you to forward or include resources within that context only.
          For foreign contexts, you will have to first obtain the context of the other application and then call forward on it.
          ServletContext otherCtx = thisContext.getContext("other context name");
          otherCtx.forward("path")
          And you will have to check your server documentation on how to achieve cross context functionality. In weblogic, its available by default whereas in tomcat, it has to be specifically enabled in the context.xml file.

          Why dont you do a simple redirect ?
          • 2. Re: RequestDispatch.forward to another context
            990719
            Thanks for your reply.

            I dont want to change the change the URL in the browser. If i use sendRedirect then it will change the URL in the browser to show the forward URL.

            Thanks,
            • 3. Re: RequestDispatch.forward to another context
              ramp
              987716 wrote:
              Thanks for your reply.

              I dont want to change the change the URL in the browser. If i use sendRedirect then it will change the URL in the browser to show the forward URL.

              Thanks,
              ok - so then the only option is to obtain the foreign application context.