Include files from context differents How do I include an HTML file in my JSP file when the HTML file is located within a different servlet context?

Alessandro A. Garbagnati

Unfortunately either <jsp:include .../> and the <%@ include .../> directive are meant to be used with URL that are relative to the context. There are two way, anyway, to achieve your goal:

1) This will work ONLY if the jsp page you want to grab is within the same virtual machine (i.e.: is another context of the same 'server'). Suppose you have two context 'CTX1' and 'CTX2' and you want to include the file '/CTX2/include_me.jsp' in your page, you can do this:

    ServletContext     ctx2 = application.getContext("/CTX2/include_me.jsp");
    RequestDispatcher rd = ctx2.getRequestDispatcher("/include_me.jsp");
    rd.forward(request, response);
2) The second solution is the old URLConnection solution that will allow you to get the result of a jsp page that reside on another context on another server, even through the net. There are many FAQ and Forum answers regarding this.
0 Comments  (click to add your comment)
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



About | Sitemap | Contact