In a custom tag, is it possible to access a scripting variable defined earlier in the page? I know you can set scripting variables in a custom tag with a TEI class, but what about using a variable defined in the page inside the tag?

Serge Knystautas

No, you cannot access scripting variables in a custom tag. Scripting variables are locally declared objects, defined within the scope of the JSP page (the service method of the generated servlet). Your tag is a separate object and has no way to access those locally declared objects.

A convenient way to pass scripting variables to your tag (aside from using the TLD and defining setter methods), is to store your scripting variables as a request or page attribute, e.g., request.setAttribute("attrName", myScriptVariable). Your tag class can then access it using request.getAttribute("attrName").

0 Comments  (click to add your comment)
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

About | Sitemap | Contact