You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Paul Krier <pk...@motive.com> on 2000/03/22 00:47:14 UTC
Servlet in Tag Bean?
I need to gain access to a servlet from within a tag bean. I have access to
the PageContext object and via that to the ServletContext object, but the
getServlet method on ServletContext object is deprecated. The only other way
I can think of to get a reference to a servlet from with in a tag is to
force the developer to use a servlet tag before the tag associated with the
bean that needs the servlet. I think that I could then get at it via the
getAttribute method on PageContext. This seems rather error prone to me and
I would like to find a better way (assuming that this actually works, of
course). Any ideas?
thanks
paul
Re: Servlet in Tag Bean?
Posted by cm...@mytownnet.com.
Why is it that you feel the need to access the servlet from within the
tag? (The same issue applies to beans in general -- not just to custom
tags.)
For most people, the answer to this has been one of the following:
* I am using variables in my servlet
to store "global" objects, and I
want to access them from various places
within my web application.
* I am using methods in my servlet as
a place to put shared logic -- a class
library, if you will.
If either of these are your primary motiviation, I would urge you to
consider migrating the data and methods into individual objects, stored as
servlet context attributes (in JSP, these would be beans with
"application" scope). Doing this accomplishes the desired sharing,
without requiring references to the servlets themselves -- getServlet()
was deprecated for valid issues related to security, as well as the fact
that it made implementing a distributed servlet container much more
complex.
If there are other issues, you can ask further about them. The
appropriate design of web applications has been a moving target because
the functionality of the underlying platform has been changing -- but
there are starting to be some general guidelines that make a lot of sense.
Craig McClanahan
On Tue, 21 Mar 2000, Paul Krier wrote:
> I need to gain access to a servlet from within a tag bean. I have access to
> the PageContext object and via that to the ServletContext object, but the
> getServlet method on ServletContext object is deprecated. The only other way
> I can think of to get a reference to a servlet from with in a tag is to
> force the developer to use a servlet tag before the tag associated with the
> bean that needs the servlet. I think that I could then get at it via the
> getAttribute method on PageContext. This seems rather error prone to me and
> I would like to find a better way (assuming that this actually works, of
> course). Any ideas?
>
> thanks
>
> paul
>