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?
Pramod KumarConnect With a Mentor Commented:
<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:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.