This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JSP and the fly likes <jsp:setProperty> sets null values in the bean Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "<jsp:setProperty> sets null values in the bean" Watch "<jsp:setProperty> sets null values in the bean" New topic
Author

<jsp:setProperty> sets null values in the bean

Uma Bandaru
Ranch Hand

Joined: Jul 30, 2009
Posts: 31
Hi,

I am using <jsp:setProperty> in my JSP page to populate values in the bean and passing it over servlet through session. In my servlet, I am able to retrieve the bean object, but all its properties are null. Any insight on this?

JSP PAGE:
<jsp:useBean id="job" type="model.JobOrderBean" class="model.JobOrderBean" scope="session"/>
<jsp:setProperty name="job" property="*"/>

SERVLET:
job = (JobOrderBean) request.getSession().getAttribute("job");
System.out.println("getAccess:" + job.getAccess()); // It prints null

Thanks,
Uma Bandaru
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Uma Bandaru wrote:
JSP PAGE:
<jsp:useBean id="job" type="model.JobOrderBean" class="model.JobOrderBean" scope="session"/>
<jsp:setProperty name="job" property="*"/>

So, are you submitting a form to Jsp and then setting form values into a bean? Hope you understand the attribute property="*"
Uma Bandaru
Ranch Hand

Joined: Jul 30, 2009
Posts: 31
My JSP Page contains the <usebean> and <setProperty> tags and also the form. The form field names match the bean properties names.

Code in JSP PAGE:


Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Uma, you are submitted the form to a servlet and there you need to get and set the form values to a bean by initialize the bean. in old days people used only jsps in some of applications. in that kind of application jsp form submitted to a jsp. and you can use useBean action tag to set the submitted values to a bean instead of scriptlets in that jsp.

in your case useBean is processed long back by Jsp engine and the scope(request) is completed when the response sent to browser.

what you have to do now: just get the submitted value in servlet and set the values into the bean, dont forget to initialize the bean before set the values.
Uma Bandaru
Ranch Hand

Joined: Jul 30, 2009
Posts: 31
Mr. Venkataswamy,

Can you please explain to me how I can get those values in my servlet?
Also, I changed the scope from request to session.

The code in my servlet currently looks like


And it prints:
getAccess:null
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Uma Bandaru wrote:



Hi Uma,

simple answer is dont use jsp:useBean here! get the field value in servlet and instantiated a new bean instead of taking from session scope and set the value as in

now bean is ready, make a cup of copy for me!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: <jsp:setProperty> sets null values in the bean
 
Similar Threads
session scopt problem
problem using javabean in JSP
jsp:useBean
returning a resultset
getting session value in JSP