If you want to output jsp code from inside jsp code then you need to use jsp:text and CDATA. I never remember the format, so I’m posting it here for next time ![]()
test.jsp
<%@ page info="a template to make another jsp page"
import="java.io.*"
import="java.util.*"
%>
<jsp:text><![CDATA[
<%@ page info="the generated jsp page"
import="java.io.*"
import="java.util.*"
%>
<%@include file="header.jsp" %>
]]></jsp:text>
<!-- this jsp outputs some dynamic content -->
<%@include file="content.jsp" %>
<jsp:text><![CDATA[
<%@include file="trailer.jsp" %>]]>
</jsp:text>
So the output from this jsp is:
<%@ page info="the generated jsp page"
import="java.io.*"
import="java.util.*"
%>
<%@include file="header.jsp" %>
This is the output from content.jsp
Today is Thursday
<%@include file="trailer.jsp" %>
Which is the copied (as a file) to the servlet engine for use with the template engine.
I do this because I’m using jsp as a templating engine. The trouble is that I can’t find an easy way to dynamically include a jsp page “inline” from a jsp. (where this jsp page itself is generated from a text file). Yes it sounds a little convoluted, but I’m trying to make the source pages as simple as possible, yet still have access to the rich functions that I provide elsewhere (like domain name assignment for images and css).