Wednesday, April 8, 2009

How to construct a JSP PageContext outside a JSP

I think it's the third time I was asked how to get a JSP servlet PageContext when you are not on a JSP. The solution is the following:

JspFactory jspxFactory = JspFactory.getDefaultFactory();
PageContext pageContext = jspxFactory.getPageContext(this, request, response, null, true, 8192, true);


Tip: I got this from the decompiled servlet that is always generated from a JSP. Just look in the belly of Tomcat (work folder) and you'll find the actual Java/class file.

No comments:

Post a Comment