|
Java
SCJP 6 Exam Download
Java
SCJP 6 Exam Details
Exam Notes
for the Sun Certified Web Component Developer (SCWCD) Exam
Section
10: Designing and Developing JSPs Using JavaBeans
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.
<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”
-
First the container looks for the specified bean in the specified scope
(default scope is page), if it is not there, one will
be created. With beanName, you can specify a
serialized file for instantiating the bean from.
-
class or beanName is required, type is optional.
-
If class and beanName are not specified (only type is specified), the bean
will not be created, it should already exist in the
specified scope.
-
The specified class should not be an abstract class or an interface and
should have a public no-args constructor. If type is
specified, the instantiated class is casted to the
type. Instantiate method is used to create the bean.
-
jsp:useBean action element can have a
non-empty body, e.g. a jsp:setProperty action; the
body will be executed for newly instantiated beans
only
<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
Previous
Contents
Next
|