OCJWCD

Oracle Certified Java Web Component Developer

Oracle Certified Java Web Component Developer


M. I.
Diese Lernkarten decken fortgeschrittene Themen der JavaServer Pages (JSP) und Servlet-Technologie ab, die für Universitätsstudenten relevant sind. Sie behandeln Farben, Methoden, EL-Objekte, Standardaktionen und Sicherheitskonfigurationen in JSP, einschließlich der Verwendung von Annotationen und XML-Dateien. Die Karteikarten sind besonders nützlich für Entwickler, die sich auf Webanwendungen spezialisieren und ein tiefes Verständnis der JSP- und Servlet-Sicherheitskonzepte benötigen.
Cartes-fiches
106
Utilisateurs
1
Langue
Allemand
Catégorie
Informatique
Niveau
Université
Créé / Mis à jour
20.10.2017 / 21.10.2017

Cartes-fiches

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..

  1. request                  javax.servlet.ServletRequest
  2. reponse                 javax.servlet.ServletResponse
  3. session                  javax.servlet.http.HttpSession
                                     only available if session="true" else translation error
  4. page                       Object
                                     synonym for this
  5. pageContext       javax.servlet.jsp.PageContext
  6. application          javax.servlet.ServletContext
  7. config                    javax.servlet.ServletConfig
  8. out                          javax.servlet.jsp.JspWriter
  9. 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?

  1. 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>
  2. Deploy jar in WEB-INF/lib/

When does EL expression of form exprA.exprB or exprA[exprB] throws an expression?

  1. exprA is a List, Set or Array
    exprB is not an int
  2. exprA obtaining value with get..() raises error
  3. 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..

  1. [],.
  2. ()
  3. - (unary), not, !, empty
  4. *, /, div, %, mod
  5. +, - (binary)
  6. <, lt, >, gt, <=, le, >=, ge
  7. ==, eq, !=, ne
  8. &&, and
  9. ||, or
  10. ?..:

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

  1. setPageContext()
  2. setParent() 
  3. invoke attribute setters
  4. doStartTag()
  5. doAfterBody()
  6. doEndTag()

Lifecycle of SimpleTag: setJspContext(), invoke attribute setters, destroy handlers, setParent(), doTag(), Instantiate, setJspBody()

  1. Instantiate
  2. setJspContext()
  3. setParent()
  4. invoke attribute setters
  5. setJspBody()
  6. doTag()
  7. Destroy handler

 

Return values for int doStartTag();

  1. EVAL_BODY_INCLUDE
  2. SKIP_BODY
  3. EVAL_BODY_BUFFERED

Return values for int doAfterBody()?

  1. EVAL_BODY_AGAIN
  2. SKIP_BODY

Étudier