posted 22 years ago
Chris,
Your servlet is not actually accessing the fields of your bean by using getAttribute().
To access the form fields, use getParameter() as you described before, but this does NOT access the bean either.
To access variables you have placed into the attribute space of request, session or application object, use the getAttribute() method of the object you used setAttribute() on. In your example, you never use setAttribute() on any object *explicitly*, so that's why you are getting nulls. There is no attribute called firstName. There is though, a parameter of that name, based on your form submission, which is why your example used to work. But you were never getting it from the bean.
Javabeans *implicitly* set the instance of the javabean object into whatever scope you specify in the scope parameter of jsp:useBean
But to use it in a servlet would be a two-step process. First retrieve the bean from the proper scope...
indexBean foo = (indexBean) session.getAttribute("indexBeanId");
*then* retrieve the items from the bean...
String firstName = foo.getFirstName();
[ February 24, 2003: Message edited by: Mike Curwen ]