bean setter from jsp page


when you declare bean setter as below from jsp page

<jsp:useBean id="sBean" class="cs.BB"
             scope="application/page/session/request" />

<jsp:setProperty name="sBean" property="*" />

what  values does it set with.

I see sBean has some default values.

While getting in jsp as below does it get default values

<jsp:getProperty name="sBean" property="gWith" /></H2>

how does changing scopes like application/page/session/request

change the output?
Please advise.

Any links resources ideas highly appreciated. Thanks in advance
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Pramod KumarCommented:
<jsp:useBean id="sBean" class="cs.BB" scope="request" />
If the bean instance does not exists: This will create the bean instance(sBean) with default values
If the bean instance exists: This will get the instance with existing values in the properties

<jsp:setProperty name="sBean" property="*" />
The setter will only be called on form submit. So the values will be same as it was in the form fields when submitted.

<jsp:getProperty name="sBean" property="gWith" />
This will be called on page load and the property value will be same which was on the bean while loading the page

Regarding scope please hit below link:

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
gudii9Author Commented:
The link is not working for me. can you please advise.
Pramod KumarCommented:
Text from the same link:

The availability of a JSP object for use from a particular place of the application is defined as the scope of that JSP object. Every object created in a JSP page will have a scope. Object scope in JSP is segregated into four parts and they are page, request, session and application.

    ‘page’ scope means, the JSP object can be accessed only from within the same page where it was created. The default scope for JSP objects created using <jsp:useBean> tag is page. JSP implicit objects out, exception, response, pageContext, config and page have ‘page’ scope.
    A JSP object created using the ‘request’ scope can be accessed from any pages that serves that request. More than one page can serve a single request. The JSP object will be bound to the request object. Implicit object request has the ‘request’ scope.
    ‘session’ scope means, the JSP object is accessible from pages that belong to the same session from where it was created. The JSP object that is created using the session scope is bound to the session object. Implicit object session has the ‘session’ scope.
    A JSP object created using the ‘application’ scope can be accessed from any pages across the application. The JSP object is bound to the application object. Implicit object application has the ‘application’ scope.
gudii9Author Commented:
>> page
>>    ‘page’ scope means, the JSP object can be accessed only from within the same page >>where it was

JSp Object mentioned in the link means sBean in my example right? please advise

<jsp:useBean id="sBean" class="cs.BB"
             scope="application/page/session/request" />
Pramod KumarCommented:
Yes, you are correct
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.