OCJWCD
Oracle Certified Java Web Component Developer
Oracle Certified Java Web Component Developer
-
- 1 / 106
-
Flashcards
Asynchronous dispatching default value?
<async-supported>false</async-supported>
Turn on asynchronous dispatching in web.xml?
<servlet>
<async-supported>true</async-supported>
</servlet>
<filter>
<async-supported>true</async-supported>
</filter>
Turn on asynchronous dispatching using annotations..
@WebServlet(asyncSupported=true)
@WebFilter(asyncSupported=true)
How to declare a resource in web.xml?
<resource-ref>
<res-ref-name>jdbc/mydb</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>
How to declare a resource using annotations?
@Resource(name = "jdbc/New")
javax.sql.DataSource mydb;
How to inject an Entity Manager?
@PersistenceContext
EntityManager em;
How to inject an Entity Manager Factory?
@PersistenceUnit
EntityManagerFactory emf;
Create EntityManager using:
EntityManager em = emf.createEntityManager();
EntityManager vs EntityManagerFactory
EntityManager
- NOT thread-save
EntityManagerFactory
- thread-save
JSP page directive example (JSP page and JSP document syntax)
<%@ page import="java.io.*, java.util*" session="true" contentType="text/html" isELIgnored="false" isErrorPage="false" %>
<jsp.directive.page import="java.io.*,java.util*" session="true" contentType="text/html" isELIgnored="false" isErrorPage="false" />
contentType: text/html for jsp pages, text/xml for jsp documents
JSP taglib directive example (JSP page and JSP document syntax)..
<%@ taglib tagdir="/WEB-INF/tags" uri=”http://www.cool.ch/tld" prefix="c" %>
<jsp:root xmlns:c=”http://www.cool.ch/tld” />
Either uri or tagdir attribute should be declared. Else translation error occurs.
JSP include directive example (JSP page and JSP document syntax)..
<%@ include file="header.html" %>
<jsp:directive.include file="header.html" />
Starting with "/" is relative to root. Else relative to current page
List implicit JSP objects..
- request javax.servlet.ServletRequest
- reponse javax.servlet.ServletResponse
- session javax.servlet.http.HttpSession
only available if session="true" else translation error - page Object
synonym for this - pageContext javax.servlet.jsp.PageContext
- application javax.servlet.ServletContext
- config javax.servlet.ServletConfig
- out javax.servlet.jsp.JspWriter
- exception java.lang.Throwable
only available if isErrorPage="true"
JSP static vs dynamic inclusion
Static
<%@ include file="banner.html" %>
<jsp.directive.include file="banner.html" />
Dynamic
<% pageContext.include("banner.html"); %>
<jsp:include page="banner.jsp" />
How to disable scripting and what's the effect?
<jsp-config>
<jsp-property-group>
<scripting-invalid>true</scripting-invalid>
</jsp-property-group>
</jsp-config>
Default: false
It disables <%.. %>, <%= .. %>, <%! .. >, <jsp.scriplet> .. <\jsp.scriplet>, <jsp.expression>.. <\jsp.expression>, <jsp.declaration> .. <\jsp.declaration>
How to disable EL support and what's the default value?
<jsp-config>
<jsp-property-group>
<el-ignored>true</el-ignored>
</jsp-property-group>
</jsp-config>
or
<% page isELIgnored="true" %>
Default: false
How to create a web fragment?
- Declare fragment in META-INF/web-fragment.xml
<web-fragment>
<name>MyLib</name>
<context-param>
<param-name>AppName</param-name>
<param-value>My Fragment Application</param-name>
</context-param>
<ordering>
<after>StorageLib</after>
</ordering>
</web-fragment> - Deploy jar in WEB-INF/lib/
When does EL expression of form exprA.exprB or exprA[exprB] throws an expression?
- exprA is a List, Set or Array
exprB is not an int - exprA obtaining value with get..() raises error
- exprA is a JavaBean
exprB is not a valid property
EL empty operator is true when ..
- variable=null
- string.length = 0. (="")
- array.length = 0
- Collection.size=0
Order EL operator precedence..
- [],.
- ()
- - (unary), not, !, empty
- *, /, div, %, mod
- +, - (binary)
- <, lt, >, gt, <=, le, >=, ge
- ==, eq, !=, ne
- &&, and
- ||, or
- ?..:
Standart action jsp:useBean Syntax?
<jsp:useBean id="var-name" scope="var-scope" attrList>
body (template text, other actions, scripting elements,..)
</jsp:useBean>
Valid attrList:
- class="class_name"
- class="class_name" type="generalised_class"
- beanName="bean_class" type="var_type"
- type="class_type"
Standart action jsp:setProperty Syntax?
- <jsp:setProperty name="var_name" property="*" />
- <jsp:setProperty name="var_name" property="property_name" value="val" />
- <jsp:setProperty name="var_name" property="property_name" param="req_param" />
value and param cannot appear together!
It never contains body content!
Standart action jsp:getProperty Syntax?
<jsp:getProperty name="var_name_of_bean" property="prop_name" />
Value is send directly into out implicit object.
It never contains body content!
JSTL Core: <c:out>
Like <%= .. >, but for expressions.
<c:out value="expression" escapeXml="true" default="" />
expression is dynamic and can be EL or scriptlet
JSTL Core: <c:catch>
Catches any Throwable that occurs in its body and optionally exposes it.
<c:catch var="page_var_name" />
JSTL Core: <c:set>
Sets the result of an expression evaluation in a 'scope'.
<c:set target="obj_target" property="prop_name" value="expression" />
<c:set var="var_name" scope="page" value="expression" />
expression is dynamic and can be EL or scriptlet
JSTL Core: <c:remove>
Removes a scoped variable (froma a particular scope, if specified).
<c:remove var="var_name" scope="var_scope" />
If var_scope is ommitted, the var_name will be removed from all scopes.
JSTL Core: <c:if>
Simple conditional tag, wich evaluates its body if the supplied condition is true and optionally exposes a Boolean scripting variable representing the evaluation of this condition.
<c:if test="test_cond" var="var_name" scope="page" >
..
</c:if>
test_cond can be EL or scriplet
var_name must be static
JSTL Core: <c:choose>, <c:when>, <c:otherwise>
Simple conditional tag that establishes a context for mutually exclusive conditional operations, marked by <when> and <otherwise>
<c:choose>
<c:when test="condition" >
<\c:when>
<c:otherwise>
<\c:otherwise>
<\c:choose>
condition can be EL or scriplet
JSTL Core: <c:forEach>
The basic iteration tag, accepting many different collection types and supporting subsetting and other functionality
<c:forEach begin="index1" end="index2" step="step_length" >
...
</c:forEach>
<c:forEach items="collection_obj" var="var_name" begin="index1" end="index2" step="step_length"
varStatus="varStatus_name" >
...
</c:forEach>
JSTL Core: <c:forTokens>
Iterates over tokens, separated by the supplied delimiters
<c:forTokens items="token_string" delims="separator_sequence" begin="index1" end="index2" step="step_length" var="var_name" varStatus="varStatus_name" >
...
</c:forTokens>
JSTL Core: <c:url>
Creates a URL with optional query parameters.
<c:url value="url_expression" context="app_context" var="var_name" scope="page" />
JSTL Core: <c:import>
Retrieves an absolute or relative URL and exposes its contents to either the page, a String in 'var', or a Reader in 'varReader'.
<c:import url="resource_url" context="app_context" varReader="reader_obj" var="var_name" scope="page" charEncoding="ISO-8859-1" />
JSTL Core: <c:redirect>
Redirects to a new URL.
<c:redirect url="redirect_url" context="app_context" />
JSTL Core: <c:param>
Adds a parameter to a containing 'import' tag's URL.
<c:param name="param_name" value="param_value" />
Base interface of all tag handler classes?
javax.servlet.jsp.tagext.JspTag
(javax.servlet.jsp.tagext.Tag before JSP 2.0)
Base interface of all classic tag?
javax.servlet.jsp.tagext.Tag
Lifecycle of IterationTag: doStartTag(), setPageContext(), doAfterBody(), doEndTag(), setParent(), invoke attribute setters
- setPageContext()
- setParent()
- invoke attribute setters
- doStartTag()
- doAfterBody()
- doEndTag()
Lifecycle of SimpleTag: setJspContext(), invoke attribute setters, destroy handlers, setParent(), doTag(), Instantiate, setJspBody()
- Instantiate
- setJspContext()
- setParent()
- invoke attribute setters
- setJspBody()
- doTag()
- Destroy handler
Return values for int doStartTag();
- EVAL_BODY_INCLUDE
- SKIP_BODY
- EVAL_BODY_BUFFERED
Return values for int doAfterBody()?
- EVAL_BODY_AGAIN
- SKIP_BODY