Search code examples
javaformsjsppopulate

JSP form and object


I want to ask you how to populate form in jsp (form:form or typically html form) with existed java object's attributes. And after changing them, how can I save this property? I googled for long but I cannot find anything about that. Thanks for advance for help.


Solution

  • That depends on the frameworks you use.

    If you use any component based MVC frameworks, the binding between your form, your object can be done. So that your form will be pre-populated with the values available in your object and vice-versa. Example frameworks are JSF, Spring MVC

    If you want to do it manually

    while generating form in your JSP, you can manually iterate through the java object in JSP and assign value to the form fields using scriptlets For example

    <input type="text" name="name" value='<%=yourObject.getField()%>' />