tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Craig R. McClanahan" <>
Subject Re: ServletContext.setAttribute()
Date Mon, 17 Jul 2000 21:35:31 GMT
Mason Jones wrote:

> Craig McClanahan wrote:
> >In the JSP page, you can retrieve this by using a scriptlet, or (better) by a
> >bean with request scope:
> >
> >    <jsp:useBean id="formMessage" scope="request" class="java.lang.String"/>
> >    The message is <%= formMessage %>
> The one question this leaves me with is the use of <%= formMessage %>
> here instead of a getProperty from the bean. What method would
> end up being called in the jsp above? Sorry if that's an obvious
> question...

In the scenario above, the "bean" is actually a String itself, instead
of an
object that has a property returning a String.  So, there will not
really be any
method call to your bean method; instead, the contents of "formMessage"
will be
included in the generated page.  In other words, in the generated
servlet you
would see something like this:

    String formMessage = (String) request.getAttribute("formMessage");
    writer.print("The message is");

which relies on the fact that <jsp:useBean> does two different things
for you --
it creates or acquires references to objects in the appropriate scope,
and it also
creates a scripting variable (that is, a local variable within the
service method
of the generated servlet) with the name you specify as the "id".

> Thanks again.
> ________________________________________
>   Mason Jones              mason(at)


View raw message