tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Erik Price <>
Subject Re: instantiating a bean in a Servlet, not a JSP
Date Fri, 10 Jan 2003 22:23:24 GMT

Paul Yunusov wrote:

>>My first guess was that in LoginServlet I could call
>>   // "ub" is reference variable of instantiated UserBean
>>   HttpSession session = getServletContext().getSession();
>>   session.setAttribute("nameOfInstance", ub);
>>But I do not think that this is right.  Later JSPs can access this
>>instance of UserBean using id="ub" ????
> No, the line of thought is correct but there are two problems:
>   1) there is no getSession() in ServletContext, use getSession() in 
> HttpServletRequest. (HttpSession, as the name suggests, is specific to HTTP 
> while ServletContext is application layer protocol agnostic).
>   2) id attribute in the jsp:useBean tag would be "nameOfInstance", not "ub".

Oh, okay -- a slip of the mind there.  Is this the official way to do 
it, because I can't find in my book (Core Servlets) where it says that 
the <jsp:useBean> tag knows to look in the session for the string used 
in the "id" attribute.

I want to avoid using a workaround since I'm just starting out.

Thanks again Paul!


To unsubscribe, e-mail:   <>
For additional commands, e-mail: <>

View raw message