The following value of JavaBean's scope attribute has local variable.
- APage
- BRequest
- CSession
- DApplication
With page scope the bean is just bound to a local variable for the current page.
MCQs, short and long questions from lecture 37.Lecture 37 ki MCQs, short aur long sawal.
8 MCQs · 21 short · 3 long questions · 8 MCQs from past papers8 MCQs · 21 short · 3 long sawal · 8 MCQs past papers se
The following value of JavaBean's scope attribute has local variable.
With page scope the bean is just bound to a local variable for the current page.
JSP action elements allow us to work with _____________.
Action elements such as jsp:useBean, jsp:setProperty and jsp:getProperty work with JavaBeans.
Which of the following is a correct order for Bean scope in JSP page from most visible to least visible?
Application scope is widest, then session, then request, and page is narrowest.
Which of the following is not a correct scope when a JavaBean is used with JSP?
Bean scopes are page, request, session and application; response is not a scope.
Using the following value of JavaBean's scope attribute, the bean object is stored in ServletContext.
Application scope stores the bean in the ServletContext, shared by the whole web application.
JSP ________ action element is used to obtain a reference to an existing JavaBean object.
jsp:useBean locates an existing bean in the given scope or creates one.
The default value of scope attribute in JSP useBean action element is ___________.
If no scope is given, jsp:useBean uses page scope.
Which of the following is a correct order for Bean scope in JSP page from least visible to most visible?
Page is narrowest, then request, session, and application is widest.
No MCQs match this filter.Is filter mein koi MCQ nahi.
What impact a JavaBeans object can produce when it is stored in Servlet Request object?
With request scope the bean is stored in the ServletRequest object. It is available to the current page and to every servlet or JSP to which the same request is forwarded or included. When the response is sent and the request ends, the bean is no longer available; a new request does not see it.
Why we use JSP action elements and what are there formats?
Action elements are XML-style tags that make the container perform an action at request time, such as working with JavaBeans, including or forwarding to other resources and passing parameters, without Java code. Format: <jsp:actionName attribute="value" ... /> or with a body <jsp:actionName ...> ... </jsp:actionName>. Examples: <jsp:useBean>, <jsp:setProperty>, <jsp:getProperty>, <jsp:include>, <jsp:forward>, <jsp:param>, <jsp:plugin>.
What is impact a java bean object can produce when it is stored in an application
With scope="application" the bean is stored in the ServletContext. It is shared by all users, all sessions and all pages and servlets of the web application, and it stays available until the application is stopped or the bean is removed. Changes made by one user are seen by everyone, so it suits shared data such as counters or configuration.
Write impact a java beans can produce when it is stored in page scope?
A bean in page scope is stored in the PageContext of that JSP. It is available only on the same page during the current request; it is not available to pages that are forwarded to or included, nor in later requests. It is discarded when the page finishes, so a new bean is created on every request of that page.
Java Beans actions elements example codes?
<jsp:useBean id="p" scope="page" class="vu.PersonInfo" /> <jsp:setProperty name="p" property="name" value="ali" /> <jsp:getProperty name="p" property="name" />
If we do nit set any scope element which scope element will be set as default scope element
page scope. If the scope attribute of jsp:useBean is omitted, it defaults to page.
Write Scope in order
From narrowest to widest: page, request, session, application.
The following JSP tag is equivalent to which action element? <jspforward page="vu.jsp">
It is the jsp:forward action element: <jsp:forward page="vu.jsp" />. It forwards the request to vu.jsp and is equivalent to the scriptlet: <% RequestDispatcher rd = request.getRequestDispatcher("vu.jsp"); rd.forward(request, response); %>
impact of object in java beans when using application scope?
A bean in application scope is stored in the ServletContext. Only one object is created and it is shared by all users, all sessions and all JSPs/servlets of the same web application; it lives until the application is stopped/reloaded. Any change made by one user is seen by all, so it suits common data (e.g. a hit counter) and access to it should be thread-safe.
Jsp:useBean equivalent to which of the java code?
It is equivalent to creating (or finding) an object in a scriptlet, e.g. <% MyBean m = new MyBean(); %> is the same as <jsp:useBean id="m" scope="page" class="vu.MyBean" /> (useBean first looks for an existing bean with that id in the given scope and creates a new one only if none exists).
What impact a JavaBeans object can produce when it is stored in Page scope?
It is available only within that page for the current request and is discarded afterwards.
What impact a java bean object produces when it is stored in servlet request object?
When the bean is stored in request scope, besides being bound to a local variable it is placed in the ServletRequest object for the duration of the current request. It stays available as long as the request is forwarded to other JSPs/servlets (or they are included), and it is removed when the request ends.
JSP code for action element <jsp:setProperty name = "name" value = "raza"/>
<jsp:setProperty> calls the setter method of the bean, so the equivalent scriptlet is <% name.setXxx("raza"); %>, where name is the bean id and Xxx is the property. The given tag is missing the required property attribute, for example <jsp:setProperty name="name" property="studentName" value="raza"/> is equivalent to <% name.setStudentName("raza"); %>.
What is alternative code of jsp special tag useBean?
<jsp:useBean id="m" scope="page" class="vu.MyBean" /> is equivalent to creating the object in a scriptlet: <% vu.MyBean m = new vu.MyBean(); %> (useBean also stores the object in the given scope and reuses an existing one if found.)
Write the method (syntax) of writing an action element of JSP.
JSP action elements are written in XML syntax: <jsp:actionElement attribute="value" ...> body </jsp:actionElement> or, without a body: <jsp:actionElement attribute="value" ... /> Example: <jsp:useBean id="p" class="vu.PersonBean" scope="page" />
List any two scopes of the Java Bean?
Any two of the four scopes of a JavaBean (used in jsp:useBean): page, request, session and application.
Name of action elements in java bean
JSP action elements for JavaBeans: - <jsp:useBean /> finds or creates a bean object. - <jsp:setProperty /> sets a property of the bean. - <jsp:getProperty /> gets a property value of the bean and writes it to the output.
What is the value of scope attribute in JSP?
The scope attribute of <jsp:useBean> can have one of four values: page, request, session or application. If the scope attribute is omitted, the default value is page.
In JSP useBean action element an attribute scope is used. What are possible values of scope attribute? If we omit scope attribute then which default value will be used?
The scope attribute of <jsp:useBean> can have one of four values: page, request, session or application. If the scope attribute is omitted, the default value is page.
See the code given below and convert scriptlet tag to equivalent jsp useBean action element. Consider StudentBean class is in package academic. <% StudentBean bean = new StudentBean(); %>
<jsp:useBean id="bean" class="academic.StudentBean" />
What impact a JavaBeans object can produce when it is stored in an Application?
When a bean is stored in application scope (<jsp:useBean ... scope="application"/>) it is saved as an attribute of the ServletContext. Only one object is created for the whole web application, it is shared by all pages, servlets, users and sessions, and it lives until the application is stopped or the attribute is removed. Any change made by one user is visible to all users, so it suits global data (e.g. a hit counter or common settings), access to it may need synchronization, and it keeps using memory for the whole life of the application.
What impact have java bean object can produce when it store in session objects?
With scope="session" the bean is bound to a local variable and also stored in the HttpSession of the current user. It stays available to every page and servlet that the same user visits, across many requests, whether the request is forwarded or a new request is made, until the session ends (timeout or invalidate()). Other users have their own session, so they get their own bean.
What are action elements of JSP? How these are written.
Action elements are XML-style tags that make the container do something at request time, such as working with JavaBeans, including or forwarding to other resources and passing parameters, without Java code. They are written as <jsp:actionName attribute="value" ... /> or with a body <jsp:actionName ...> ... </jsp:actionName>. Examples: <jsp:useBean id="m" class="vu.MyBean" scope="session"/> <jsp:setProperty name="m" property="name" value="ali"/> <jsp:getProperty name="m" property="name"/> <jsp:include page="header.jsp"/> <jsp:forward page="next.jsp"/> <jsp:param name="id" value="1"/>
What impact a JavaBeans object can produce when it is stored in Session object?
A bean in session scope is stored in the user’s HttpSession. It is available to all JSPs and servlets that the same user visits during that session, across many requests, until the session times out or is invalidated. Each user gets a separate copy, so it suits user-specific data such as login information or a shopping cart; it also uses server memory for every active session.