Hi!
I want to do certain initializations before a jsp page is rendered. I
plan to do this by using the 'extends' keyword in my jsp page and
write a class that extends GenericServlet and implements
HttpJspPage. The problem is that I want to get a handle to PageContext
before page rendering is started, but I can't get it! I only get
null. It seems PageContext is made available somewhere between
the call to _jspService() and the jsp-page is "entered".
Below is the code. How do I get a working handle to PageContext? If it
is not possible, can I somehow get a handle to JspWriter before the call to
_jspService()?
I am using Tomcat 4.0.2
Thanks,
Claes Holmerson
public abstract class TemplateJspPage
extends GenericServlet implements HttpJspPage
{
/**
* Constructor.
*/
public TemplateJspPage()
{
}
/**
* Initalizes the page.
* @see javax.servlet.Servlet
*/
public void init(ServletConfig config)
throws ServletException
{
super.init(config);
jspInit();
}
/**
* Stub implementation here, only the JSP page may redefine.
* @see javax.servlet.jsp.HttpJspPage
*/
public void jspInit()
{
}
public void service(ServletRequest request, ServletResponse response)
throws ServletException, IOException
{
HttpServletRequest req = (HttpServletRequest) request;
HttpServletResponse resp = (HttpServletResponse) response;
PageContext pageContext =
JspFactory.getDefaultFactory().getPageContext(this,
request,
response,
null,
true,
JspWriter.DEFAULT_BUFFER,
true);
System.out.println("TemplateJspPage pageContext = " + pageContext);
//pageContext is null!!!!
//render...
_jspService(req, resp);
}
/**
* Abstract here, the JSP engine will implement,
* the JSP page may _not_ redefine.
* @see javax.servlet.jsp.HttpJspPage
*/
public abstract void _jspService(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException;
/**
* @see javax.servlet.Servlet
*/
public void destroy()
{
super.destroy();
jspDestroy();
}
/**
* Stub implementation here, only the JSP page may redefine.
* @see javax.servlet.jsp.HttpJspPage
*/
public void jspDestroy()
{
}
--
Claes Holmerson
Polopoly - Cultivating the information garden
Kungsgatan 88, SE-112 27 Stockholm, SWEDEN
Direct: +46 8 506 782 59
Mobile: +46 704 47 82 59
Fax: +46 8 506 782 51
[EMAIL PROTECTED], http://www.polopoly.com
--
To unsubscribe, e-mail: <mailto:tomcat-user-unsubscribe@;jakarta.apache.org>
For additional commands, e-mail: <mailto:tomcat-user-help@;jakarta.apache.org>