When a user is logged in, a user object is placed in session. This way I can access all attributes. I want to have a form where the user can the attributes.
The servlet that is called:
The current values display in the form. After changing any of the fields and pressing submit, I expect to see the new values from the servlet, but it just prints out the old values. I have no idea why. I obviously have setters in the User class. I do the same thing in user registration, which works perfectly. The only difference is that in the registration form, I instantiate the object with a <jsp:useBean>, but it should be working when accessing an existing object from the session too, right??
Maybe I'm wrong, or missing something obvious, it should be easy to get this working, but I've been stuck here for too long....
Andre Solberg wrote:After changing any of the fields and pressing submit, I expect to see the new values from the servlet
And just why would you expect that? If you haven't done anything to update the properties of the bean, why would you expect them to be updated?
Grab the info from the request and update the bean properties.
User object in the session scope must have changed/updated, may be by using jsp:setproperty tag(i guess the scope attribute in jsp useBean tag must have the value as session).
Andre Solberg wrote:The only difference is that in the registration form, I instantiate the object with a <jsp:useBean>
Difference between these two is, first one takes a copy of User object from session and updates copied User object 's attribute and updates it into session; Second one directly uses the User object from session.
I am little late
I handle the registration in a separate jsp instead of servlet. I forgot about the <jsp:setProperty name="user" property="*"/> within the <jsp:useBean>.
I guess I just thought there was some magic that automatically filled the bean with the values from the fields as long as the setters where right ...
But when doing this in a servlet, does that mean I have to manually fill in each and every property from the request and put in in the bean? I can't put the <jsp:setProperty> in before I submit or in the servlet? If so, then damn...
Thanks for helping!