Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / October 2005

Tip: Looking for answers? Try searching our database.

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

Thread view: 
John Davison - 12 Oct 2005 20:07 GMT
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.
Sikri - 12 Oct 2005 20:41 GMT
The above example might work but may be 'kludgy'.
But a suggested answer would be to use struts as the framework.
It will:
1. Map your form to a bean.
2. Also provide a controller servlet
For more information, please follow this link:
http://struts.apache.org.

- VS
Viv - 13 Oct 2005 12:33 GMT
I haven't find any utility that map the data to a bean, so i end up
with my own utility. Reflection mechanism can work it for u, if u have
that much of time.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.