Access of JSP of another web application


Web tier: servlets, JSP, Web frameworks: Access of JSP of another web application

  1. Access of JSP of another web application (1 messages)

    We need to access the JSPs that are in a web application that is not deployed as WAR, from servlets in an application that is deployed as WAR. How?

    Also if possible, can we share the servlet context data from WAR deployed application to JSPs that we execute so.

  2. Access of JSP of another web application[ Go to top ]

    Access in what respect? If you want to do redirects, then that's pretty easy so I'm not going to answer that. If you're talking about sharing context data, I've only had luck with the technique at the bottom. First I'll explain why you can't directly access resources in another context.

    If you have a servlet in a 'myapp1' context (i.e. http://localhost/myapp1/servlet/Controller) and it tries to do something like this:


    getServletConfig().getServletContext().getRequestDispatcher("/myapp2/process.jsp").forward(request, response);
    // and similarly, .include(request, response);

    then it'll probably throw an exception or will report that it cannot find the file. The parameter of getRequestDispatcher is automatically appended to the calling servlet's context path (i.e. so in this case, it will try to forward the request to: http://localhost/myapp1/myapp2/process.jsp) which is probably not what you wanted.

    Sharing of attributes stored in the servlet context is possible:

    ServletContext sc = getServletConfig().getServletContext().getContext("/mycontext");

    One you have a ServletContext object, you can set and get attributes (objects).

    Hope this helps somewhat.