<jsp:include> with pages outside a web application


Web tier: servlets, JSP, Web frameworks: <jsp:include> with pages outside a web application

  1. Hello,

    I have some 15 web appications that have common images and parts of JSPs (header, footers, tables of contents, for example). I would like to make a 'common.war' application that would contain all these common files. But as I noticed, <jsp:include> can include only pages bound to a local web context. I. e., in my application 'employees.war' in the 'index.jsp' page I would like to include a 'header.jsp' from the 'common.war' application, that is on another host ('thunder') , by using the following directive:

    <jsp:include page="http://thunder/common/header.jsp">

    But this doesn't work, because this is interpreted as "/employees/http://thunder/common/header.jsp". Obviously, this file is not found in 'employees.war'...

    Does anyone knows how to solve this problem?

    Sergei Batiuk.
  2. See Content tag from Coldtags suite:
    It does this job.
  3. Hi Dmitry,

    Thank you very much for you reply! Well, I see this is beyond the spec...

    I have tried http://www.servletsuite.com/jsp.htm but it doesn't really solves my problem. I needed to include a file from another server, not in the local filesystem.

    Browsing internet, I found an excellent solution! Take a look at http://jakarta.apache.org/taglibs/doc/io-doc/intro.html.

    Sergei Batiuk.

  4. A simple solution would be to use the RequestDispatcher, rather than the <jsp:include> tag. For example:

    ServletContext thisContext = config.getServletContext();
    ServletContext c = thisContext.getContext("/contextName");
    context.getRequestDispatcher().include(request, response);

    Maybe not the prettiest, but it works!