tomcat-users mailing list archives

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

I have another very basic question.  If it is a problem tell me to 
leave, sorry.  The index.html page has a form which lets users enter a 
username/password combo, which gets sent to LoginServlet.  LoginServlet 
performs the authentication, and if it fails then the user is redirected 
to an error page.  But if it succeeds, I want to instantiate a UserBean 
class (which I have created) and make the scope of that bean "session". 
  So that I can access this bean in later pages.

I understand that I can have my JSPs create or refer to a named bean using

<jsp:useBean id="nameOfInstance"

This is fine.  But I would like to instantiate the bean in LoginServlet. 
   How can I register the bean in the session scope for later JSP's to 
retrieve it?

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" ????



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

View raw message