Tom Tucker
Tom Tucker

Reputation: 11896

Including a JSP Page Programmatically

I need to include a JSP page in a Tag class. I believe the standard way to include a JSP page within another JSP page using API is this:

request.getRequestDispatcher("included.jsp").include(request, response);

However, I noticed that the included page is rendered at the top of the generated page, no matter where the code is located. This is true whether the code is placed in a Tag class or directly in the JSP file as scriptlet. On the other hand, the <jsp:include> action works as expected, rendering the included page where the tag appears in the JSP file.

How do I include a JSP page in a class so that it behaves the same as the <jsp:include>? There's no way to invoke the <jsp:include> action within a Tag class, is there?

Upvotes: 2

Views: 1407

Answers (2)

jt.
jt.

Reputation: 7705

Perhaps your tag class should call pageContext.getOut().flush(); prior to calling request.getRequestDispatcher("included.jsp").include(request, response);

Upvotes: 4

MJB
MJB

Reputation: 9389

I hate to be lazy, but why not just look at a JSP compiled file. for example, tomcat compiles these to \work, and you can VIEW the java it produced there.

Upvotes: 0

Related Questions