Win a copy of High Performance Python for Data Analytics this week in the Python 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:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Jj Roberts
  • Carey Brown
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

<jsp:setProperty> sets null values in the bean

 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
And will you succeed? Yes you will indeed! (98 and 3/4 % guaranteed) - Seuss. tiny ad:
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic