views:

629

answers:

4

I'm trying to create a jsp tag file but it fails to compile when I try to use pageContext.getServletConfig().getInitParameter("myInitParam")

I'm using tomcat and when I try to view a page including the file I get a jasper compile error pageContext cannot be resolved. I've also tried just using getInitParameter but it fails also. I can use the request object so I know everything else is fine.

Does anyone know a way to access init parameters set in the web.xml from a jsp tag file, preferably from within a scriptlet?

A: 

Have you tried the request rather than the pageContext? Or just off the servlet itself:

getInitParameter("myInitParam");
sblundy
A: 

Are you extending the TagSupport class?

If so, this class has a member named pageContext, the Tag interface declares a method setPageContext(PageContext pc), which the docs state

This method is invoked by the JSP page implementation object prior to doStartTag().

So you should be able to reference this.pageContext fine - unless you are extending a different class?

matt b
+1  A: 

I just found out the trick is to use one of the implicit objects, in this case config or application depending on the init-parameters scope. they are list at http://today.java.net/pub/a/today/2003/11/14/tagfiles.html

A: 

application.getInitParameter("");

Vivek Mantri