SECTION 10: DESIGNING AND DEVELOPING JSP PAGES USING JAVABEAN COMPONENTS

Section 10
10.1 For any of the following tag functions, match the correctly constructed tag, with attributes and values as appropriate, with the corresponding description of the tag's functionality:
  • Declare the use of a JavaBean component within the page.
  • Specify, for jsp: useBean or jsp: getProperty tags, the name of an attribute.
  • Specify, for a jsp: useBean tag, the class of the attribute.
  • Specify, for a jsp: useBean tag, the scope of the attribute.
  • Access or mutate a property from a declared JavaBean.
  • Specify, for a jsp: getProperty tag, the property of the attribute.
  • Specify, for a jsp: setProperty tag, the property of the attribute to mutate, and the new value.
10.2 Given JSP page attribute scopes: request, session, application, identify the equivalent servlet code.
10.3 Identify techniques that access a declared JavaBean component.

Section 10 - Designing and Developing JSP pages Using JavaBean Components

10.1 For any of the following tag functions, match the correctly constructed tag, with attributes and values as appropriate, with the corresponding description of the tag's functionality:

  1. Declare the use of a JavaBean component within the page.
  2. Specify, for jsp: useBean or jsp: getProperty tags, the name of an attribute.
  3. Specify, for a jsp: useBean tag, the class of the attribute.
  4. Specify, for a jsp: useBean tag, the scope of the attribute.
  5. Access or mutate a property from a declared JavaBean.
  6. Specify, for a jsp: getProperty tag, the property of the attribute.
  7. Specify, for a jsp: setProperty tag, the property of the attribute to mutate, and the new value.
<jsp:useBean>
<jsp:useBean id="connection"class="com.myco.myapp.myBean" scope="page" /> 
  - create if bean doesn't exist
<jsp:useBean id="connection" beanName="com.myco.myapp.myBean.ser" /> 
  - create from a serialized object
<jsp:useBean id="connection" type="com.myco.myapp.myBean" /> 
  - Bean should already exist

<jsp:useBean id="name" scope="page|request|session|application" typeSpec />

typeSpec ::=  class="className" |
                class="className" type="typeName" |
                type="typeName" class="className" |
                beanName="beanName" type="typeName" |
                type="typeName" beanName="beanName" |
                type="typeName"
    <jsp:useBean id="name" scope="page|request|session|application" typeSpec >
     body - usually this will be scriptlets or jsp:setProperty actions
    </jsp:useBean>
 
<jsp:getProperty>
<jsp:getProperty name="beanName" property="propName" />

<jsp:setProperty>

<jsp:setProperty name="bean1" property="*" />  
    -- all request parameters will be set in bean's properties (with matching names)
<jsp:setProperty name="bean2" property="user " param="username " />
 -- request parameter 'username' will be set to 'user' property of the bean
<jsp:setProperty name="bean2" property="user "  />
    -- request parameter 'user' will be set to 'user' property of the bean (since no param specified, it is assumed to have the same name as the property)
<jsp:setProperty name="bean2" property="user "  value="me" />
<jsp:setProperty name="bean2" property="user " value="<%=session.getAttribute("user") %>" />
 -- new value can be specified with an expression. If it's an expression no conversion is performed, else standard conversion is performed.

Note: value cannot be used in conjunction with param

10.2 Given JSP page attribute scopes: request, session, application, identify the equivalent servlet code.


request - HTTPServletRequest
session - HTTPServletRequest.getSession() : HTTPSession
application - GenericServlet.getServletContext() or GenericServlet.getServletConfig().getServletContext()

10.3 Identify techniques that access a declared JavaBean component.

A declared JavaBean can also be accessed using: (the name specified in the id attribute of <jsp:useBean>)

Scriptlets 
Expressions
Custom Tags

Return to top