Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

<jsp:setProperty> sets null values in the bean  RSS feed

 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!