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!

passing bean from JSP to Servlet: data loss

843841Apr 23 2003 — edited Apr 25 2003
Hi!

I am writing an application reads data from a DB, populates a bean with the data, passes the bean to a JSPs where a user can edit fields, and then sends the bean back to a Servlet. Getting the data to the JSPs is easy, but I'm having problems getting the data back to the Servlet. The JSP allows the user to edit certain bean fields, but not all fields, using a form. Next, I submit the form to another JSP (which simply does a forward to get the data to a Servlet). When the Servlet fetches the bean from the Request using req.getAttribute("mybean"), the fields that the user could edit via the form are filled in. However, the fields which the user could not edit are blank! Why is this?

I do make sure to fill in all the bean fields when the bean is created using <jsp:setProperty name="mybean" property="*"/>. Is there something else I need to do? The data IS getting to the JSP: I can print out all the bean fields using the JSP, and they are all present and correct.

Here are some code snippets which illustrate:

(1) bean is passed to a JSP which has form for editing some of the bean's fields:
<jsp:useBean id="mybean" class="com.xxx.BeanX" scope="request">
    <jsp:setProperty name="mybean" property="*"/>
</jsp:useBean>

<form name=myform method=post action="/control.jsp">
<input type=text name=myproperty size="30" maxlength="30"
       value="<jsp:getProperty name="mybean" property="myproperty"/>" >
</form>
(2) The control.jsp just does a forward:
<jsp:useBean id="mybean" class="com.xxx.BeanX" scope="request">
    <jsp:setProperty  name="mybean" property="*"/>
</jsp:useBean>
<jsp:forward page="/com.xxx.myservlet">
</jsp:forward>
(3) A servlet then gets the bean from the Request:
BeanX bean = (BeanX)req.getAttribute("mybean");
String myprop = bean.getMyproperty();
String myprop2 = bean.getMyproperty2();
(4) myprop contains the new data from the form.
myprop2 is null, even though it was set when the bean was passed to the JSP!
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 23 2003
Added on Apr 23 2003
6 comments
548 views