struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Craig R. McClanahan" <craig...@apache.org>
Subject Re: custom tags and Action servlet
Date Mon, 27 Aug 2001 23:30:24 GMT


On Wed, 22 Aug 2001, Mike D wrote:

> Date: Wed, 22 Aug 2001 16:31:17 +0000
> From: Mike D <qazwasit@hotmail.com>
> Reply-To: struts-user@jakarta.apache.org
> To: struts-user@jakarta.apache.org
> Subject: custom tags and Action servlet
>
> I have a custom tag that I've written, and I want it to talk to the Action
> Servlet (to get mappings out). How can I do this?
>
> When I'm in the Jsp, can I access the action servlet? Or is it out of scope
> by then?
>

An oldie but a goodie ...

The ActionServlet instance itself is not visible to you from within a JSP
page (or a custom tag that you are writing).  However, the mappings
themselves are visible, because they are stored in a servlet context
attribute.  Therefore, you can (in your tag class) say:

  ActionMappinges mappings = (ActionMappings)
   pageContext.findAttribute(Action.MAPPINGS_KEY,
                             PageContext.APPLICATION_SCOPE);

assuming you've imported both org.apache.struts.ActionMappings and
org.apache.struts.Action.

Take a glance through the source code for the initXxxxx methods in
ActionServlet, and you will find that basically all of the information
extracted from struts-config.xml is made available through such servlet
context attributes.

Craig


Mime
View raw message