简体   繁体   中英

How do I access init parameters from a JSP2 tag file?

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?

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

application.getInitParameter("<Name>");

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

getInitParameter("myInitParam");

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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM