Using existing data in a Struts form


Web tier: servlets, JSP, Web frameworks: Using existing data in a Struts form

  1. Using existing data in a Struts form (2 messages)

    I want to have a form where registered users can edit their details.

    This means the form has to be pre-populated with the users data. Do I simply need to set the values of the form bean from the DB in advance to do this? If so, how do I do that?

    If I'm way off track - can someone give me some clues Please? This is the last thing I need to do to get my web app running!
  2. Hi,

    public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
        UserForm userForm = (UserForm) form;

        //populate user form with data retrieved from db
        request.setAttribute("userForm", userForm);
        return mapping.findForward("success");

    Best regards, Mircea
  3. Hi Paul

    What you are planning to do is absolutely right. If you have some problems in setting some data you can directly set it to the session object and access the data from the session object. Dont forget to remove the session attribute after you have used the data. Otherwise it will create some performance problems

    You can do it in this was

    <html:text property="aa" value="{sessionattribute}"/>