aspose file tools*
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 Java 8 in Action this week in the Java 8 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!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: <jsp:setProperty> sets null values in the bean
 
Similar Threads
jsp:useBean
session scopt problem
getting session value in JSP
problem using javabean in JSP
returning a resultset