Hi all, I have a problem with a javabean. I can't get a reference in a servlet. This is what I do: 1- I open a jsp page with the following: <jsp:useBean id="cal_bean" class="Calendar_Bean" scope="session"/> Name = <%=cal_bean.getName()%> 1st time name is blank 2- the user may open a login window - which post to a servlet 3- in the servlet, I have the following code: HttpSession session = req.getSession( false ); Calendar_Bean cal_bn = (Calendar_Bean)session.getAttribute ("cal_bean") ; cal_bn.setName( str_uname ); got username using getParameter 4- when the login window is closed, I will to refresh the main page to display the user name. Problem: The username is always null even if I enter a name in the login window. Seems like the servlet doesn't have a reference to the javabean created in the jsp window. What's wrong with this? Thanks, Francois.
Originally posted by java alltheway: Hi all, I have a problem with a javabean. I can't get a reference in a servlet. This is what I do: 1- I open a jsp page with the following: <jsp:useBean id="cal_bean" class="Calendar_Bean" scope="session"/> Name = <%=cal_bean.getName()%> 1st time name is blank 2- the user may open a login window - which post to a servlet 3- in the servlet, I have the following code: HttpSession session = req.getSession( false ); Calendar_Bean cal_bn = (Calendar_Bean)session.getAttribute ("cal_bean") ; cal_bn.setName( str_uname ); got username using getParameter 4- when the login window is closed, I will to refresh the main page to display the user name. Problem: The username is always null even if I enter a name in the login window. Seems like the servlet doesn't have a reference to the javabean created in the jsp window. What's wrong with this? Thanks, Francois.
After you do: cal_bn.setName( str_uname ); try: session.setAttribute("cal_bean", cal_bn); It's possible that under some circumstances (and some appliation servers) that the bean is swapped out and then replaced from the swapped-out version if you don't re-set the attribute. Kyle
"java alltheway" your name doesn't agree with the javaranch guidelines. please take a moment and re-register after reviewing the guidelines at http://www.javaranch.com/name.jsp thanks for your cooperation. - satya