J
John Davison
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="<cut value="${id.ssn}" />"/>
First Name:
<input name="firstName" type="text" value="<cut
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.
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="<cut value="${id.ssn}" />"/>
First Name:
<input name="firstName" type="text" value="<cut
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.