Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

JSP to Servlet: Dynamically Binding Form Data to a Bean??

843838Oct 12 2005 — edited Oct 12 2005
Pardon me if this seems trivial, but I'm new to JSP/Servlets and I haven't found the answer to problem on the net.

I have an input form that is quite large. I want to dynamically bind my form data to a bean, then pass this bean to a servlet. I've found one method that works, but it seems like a hack.

The form is calling itself. If the hidden parameter "submitted" is set, then the JSP forwards to the desired servlet.
<jsp:useBean id="id" class="com.acme.IdentityBean" scope="request">
    <jsp:setProperty name="id" property="*" />
</jsp:useBean>

<c:if test="${param.submitted}">
    <jsp:forward page="MyServlet" />
</c:if>

<html>
<body>
<form action="index.jsp" method="post">

    <input type="hidden" name="submitted" value="true" />

    Social Security #:
    <input name="ssn" type="text" value="<c:out value="${id.ssn}" />"/>

    First Name:
    <input name="firstName" type="text" value="<c:out value="${id.firstName}" />"/>

    <!-- Many more input fields. They have been removed for brevity. -->

    <input type="submit" value="Submit"/>
    <input type="reset" value="Clear"/>
</form>
</body>
</html>
I have to post to this JSP in order for my jsp:setProperty to do the work of binding all the input fields to the IdentityBean. Is this the ideal pattern?

Any advice is appreciated.

~J.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 9 2005
Added on Oct 12 2005
2 comments
333 views