Head First Servlets and JSP

马上开始. 它是免费的哦
注册 使用您的电邮地址
Head First Servlets and JSP 作者: Mind Map: Head First Servlets and JSP

1. Chap 9. Using JSTL

1.1. Core Tags

1.1.1. <c:out />

1.1.1.1. Attributes

1.1.1.1.1. value

1.1.1.1.2. escapeXml attribute is optional, true as default

1.1.1.1.3. default attribute is optional, the body of the c:out tag also works as default attribute

1.1.2. <c:forEach>

1.1.2.1. Attributes

1.1.2.1.1. var

1.1.2.1.2. items

1.1.2.1.3. varSatus

1.1.2.2. can nest tags

1.1.3. <c:if>

1.1.3.1. Attributes

1.1.3.1.1. test

1.1.3.2. doesn't have an else

1.1.4. <c:choose>

1.1.4.1. <c:when>

1.1.4.1.1. test

1.1.4.2. <c:otherwise>

1.1.5. <c:set>

1.1.5.1. Variables

1.1.5.1.1. var

1.1.5.1.2. scope, default page

1.1.5.1.3. value, the body also works as value

1.1.5.2. Beans or Maps

1.1.5.2.1. target

1.1.5.2.2. property

1.1.5.2.3. value, the body also works as value

1.1.6. <c:remove>

1.1.6.1. attributes

1.1.6.1.1. var

1.1.6.1.2. scope, is optinoal if not exist remove from ALL

1.1.7. <c:import>

1.1.7.1. Attribute

1.1.7.1.1. url

1.1.7.1.2. value

1.1.7.1.3. var

1.1.7.2. add the contet from the value of url attribute to the current page, at request time (runtime) like jsp:include but it's more flexible

1.1.7.3. can reach outside of the web app

1.1.7.4. Body

1.1.7.4.1. <c:param>

1.1.8. <c:catch>

1.1.8.1. attirubte

1.1.8.1.1. var

1.1.9. <c:forTokens>

1.1.10. <c:url>

1.1.11. <c:redirect>

1.2. Errors

1.2.1. Manually

1.2.1.1. <%@ page isError="true">

1.2.1.1.1. ${pageContext.exception}

1.2.1.2. <%@ page errorPage="errorPage.jsp">

1.2.2. DD

1.2.2.1. <error-page> <exception-types>java.lang.Throwable</.. <location>/errorPage.jsp</... ...

1.2.2.2. <error-page> <exception-type>java.lang.ArithmeticException</... <location>/arimeticError.jsp</... ...

1.2.2.3. <error-page> <error-code>404</... <location>/notFoundError.jsp<... ....

1.3. TLD

1.3.1. declaration

1.3.1.1. <?xml ...> <taglib xmlns...> <tlib-verion>1.2</tlib-verion> //mandatory <short-name>Random</short-name>//mandatory <function> //to be called on EL <name>rollIt</name> <function-class>foo.DiceRoller</function-class> <function-signature>int rollDice()</function-signature> </function> <uri>randomThings</uri> //unique! <tag> <description>randome advice</description>//optional <name>advice</name>//Required <tag-class>foo.AdvisorTagHandler</tag-class>//required <body-contet>empty</body-contet>//required <attribute> <name>user</name> <required>true</required> <rtexprvalue>true</rtexprvalue> </attribute> </tag> </taglib>

1.3.1.1.1. rtexprvalue, default is false

1.3.1.1.2. body-contet

1.3.1.1.3. uri

1.3.1.2. <taglib> <taglib-uri>randomThings</.. <taglib-location>/WEB-INF/tag.tld</.. </...

1.3.2. class

1.3.2.1. extends SimpleTagSupport

1.3.2.2. override void doTag()

1.3.2.3. all setters needed

1.3.3. usage

1.3.3.1. <%@ taglib prefix="calis" uri="randomThings" %> <mine:advice user="${username}">

1.3.4. The TLD file can be placed in any subdirectory of WEB-INF

2. Chap 10. Custom tag Development

2.1. Tag handlers

2.1.1. Classic

2.1.1.1. Extend TagSupport -> IterationTag -> Tag -> JspTag

2.1.1.2. Life

2.1.1.2.1. 1. Load class

2.1.1.2.2. 2. Instantiate class (no-args constructor runs)

2.1.1.2.3. 3. Call the SetPageContext(PageContext)

2.1.1.2.4. 4. if the tag is nested setParent(Tag)

2.1.1.2.5. 5. if the tag has attributes, call attributes setters

2.1.1.2.6. 6. doStartTag()

2.1.1.2.7. 7. if the tag is NOT declared to have an empty body, AND tag is NOT invoked with an empty body, AND the doStartTag() return EVAL_BODY_INCLUDE the body is evaluated

2.1.1.2.8. 8. if the body is evauated doAfterBody()

2.1.1.2.9. 9. doEndTag()

2.1.1.3. pageContext.getOutput().println

2.1.1.4. pageContext.implicitObjects

2.1.2. Classic BodyTag

2.1.2.1. extend BodyTagSupport (implement bodyTag -> iterationTag-> Tag-> JspTag )

2.1.2.2. Life

2.1.2.2.1. 1. Load class

2.1.2.2.2. 2. Instantiate class (no-args constructor runs)

2.1.2.2.3. 3. Call the SetPageContext(PageContext)

2.1.2.2.4. 4. if the tag is nested setParent(Tag)

2.1.2.2.5. 5. if the tag has attributes, call attributes setters

2.1.2.2.6. 6. doStartTag()

2.1.2.2.7. 7. setBodyContet() if Eval_body_buffered was returned

2.1.2.2.8. 8. doInitBody()

2.1.2.2.9. 9. if the tag is NOT declared to have an empty body, AND tag is NOT invoked with an empty body, AND the doStartTag() return EVAL_BODY_INCLUDE the body is evaluated

2.1.2.2.10. 10. if the body is evauated doAfterBody()

2.1.2.2.11. 11. doEndTag()

2.1.3. Simple

2.1.3.1. Extend SimpleTagSupport --> SimpleTag --> JspTag

2.1.3.2. To deploy it, must crate a TLD that describes the tag using the same <tag> element

2.1.3.3. to use it with body, make sure the TLD <tag> for this tag does not declare <body-contet>empty. then call getJspBody().invoke(null) to cause the body to be processed

2.1.3.4. Life

2.1.3.4.1. 1. Load class

2.1.3.4.2. 2. Instantiate class (no-args constructor runs)

2.1.3.4.3. 3. Call setJspContext(jspContext)

2.1.3.4.4. 4. If the tag is nested, call the setParent(JspTag)

2.1.3.4.5. 5. If the tag has attributes, call attribute setters

2.1.3.4.6. 6. if the tag is NOT decalred to have a <body-contet>empty.... and the tag has a body, call setJspBody(JspFragment)

2.1.3.4.7. 7. doTag()

2.1.3.5. can set attribute used by the body of the tag, calling getJspContext().setAttribute() followed by getJspBody().invoke()

2.1.3.6. You can iterate over the body invoking the body (getJspBody.invoke()) in a loop

2.1.3.7. the getJspBody() return a JspFragment

2.1.3.7.1. methods

2.1.3.8. Throw a SkipPageException if you want the current page to stop processing, if the page that invoked the ta was included from another page, the including page keeps going even though the included page stops processin from the moment the exception is thrown

2.1.3.9. getJspContext().getOutput().println

2.1.3.10. getJspContext().implicitobjects

2.2. Tag

2.2.1. Apply only to tags

2.2.1.1. tag

2.2.1.2. taglib

2.2.1.3. jsp:doBdoy

2.2.2. directives but page

2.2.3. NOT Scripting

2.2.4. jsp:invoke

2.3. DynamicAttributes Interface

2.3.1. method

2.3.1.1. setDynamicAttribute(String uri, String name, object, value)

2.3.2. <tag> <attribute>... <dynamic-attribute>true</dynamic-attribute> ...

2.3.3. <%@ tag body-contet="empty" dynamic-attribute="tagAttrs">

2.4. PageContext

2.4.1. extend from JspContext

2.4.1.1. mehtods

2.4.1.1.1. getAttributes(name)

2.4.1.1.2. getAttribute(name, int scope)

2.4.1.1.3. getAttributeNamesInScope(int scope)

2.4.1.1.4. findAttribute(name)

2.4.2. methods

2.4.2.1. getRequest()

2.4.2.2. getServletConfig()

2.4.2.3. getServletCnontext()

2.4.2.4. getSession()

2.4.3. Scopes

2.4.3.1. Application

2.4.3.2. Page

2.4.3.3. Request

2.4.3.4. Session

3. Chap 11. Web App Deployment

3.1. Directory Structure

3.1.1. Webapps

3.1.1.1. NameofTheApp

3.1.1.1.1. *.jsp *html

3.1.1.1.2. WEB-INF

3.1.2. War

3.1.2.1. Webapps

3.1.2.1.1. NameofTheApp

3.2. Mapping

3.2.1. <servlet> <servlet-name>Beer</servlet-name> <servlet-class>com.example.BeerSelect</servlet-class> </servlet> <servlet-mapping> <servlet-name>Beer</... <url-pattern>/Beer/SelectBeer.do</.. ...

3.2.2. Rules

3.2.2.1. one Match

3.2.2.1.1. 1. exact Match

3.2.2.1.2. 2. directory match

3.2.2.1.3. 3 extension match

3.2.2.2. multiples match

3.2.2.2.1. choose the longest mapp

3.3. Welcome file

3.3.1. <welcome-file-list> <welcome-file>index.html</... <welcome-file>default.jsp</.. </...

3.4. initialization

3.4.1. <servlet> <servlet-name>... <servlet-class>... <load-on-startup> number </.. ...

3.5. JSP Document (XML-based dcument)

3.5.1. Directives (except taglib)

3.5.1.1. <%@ page import="java.util.*" %>

3.5.1.2. <jsp:directive.page import="java.util.*"/>

3.5.2. Declaration

3.5.2.1. <%! int y=3; %>

3.5.2.2. <jsp:declaration> int y = 3; </jsp:declaration>

3.5.3. Scriptlet

3.5.3.1. <%list.add("foo"); %>

3.5.3.2. <jsp:scriptlet> list.add("foo"); </jsp:scriptlet>

3.5.4. text

3.5.4.1. Simple text

3.5.4.2. <jsp:text> Simple text </jsp:text>

3.5.5. scripting expression

3.5.5.1. <%= it.next() %>

3.5.5.2. <jsp:expression> it.next() </jsp:expression>

3.6. EJB

3.6.1. local

3.6.1.1. <ejb-local-ref> <ejb-ref-name>ejb/Customer</.. <ejb-ref-type>Entity</.. <local-home>org.some.CustomerHome</... <local>org.some.Customer</... ......

3.6.2. remote

3.6.2.1. <ejb-ref> <ejb-ref-name>ejb</... <ejb-ref-type>Entitiy</... <home>org.some.CustomerHome</.. <remote>org.some.Customer</.. ...

3.7. env-entry

3.7.1. <env-entry> <env-entry-name>rates/discountRate</.... <env-entry-type>java.lang.Integer</.. <env-entry-value>10</... ....

3.8. Mime

3.8.1. <mime-mapping> <extension>mpg</... <mime-type>video/mpeg</... .......

4. Chap 12. Web App Security

4.1. Realm: place where authentication information is stored

4.2. Authorization

4.2.1. Step 1. Defining roles

4.2.1.1. tomcat-user.xml

4.2.1.1.1. <tomcat-users> <role rolename="Admin"/> <role rolename="Member"/> <role rolename="Guest"/> <user username="Guti" password="secret" roles="Admin, Member, Guest"/> <user username="Ted" password="Tedsecret" roles="Guest"/> ...........

4.2.1.2. DD

4.2.1.2.1. <security-role><role-name>Admin</role-name></security-role> <security-role><role-name>Member</role-name></security-role> <security-role><role-name>Guest</role-name></security-role>

4.2.1.2.2. <login-config> <auth-method>BASIC</... </...

4.2.2. Sept 2. Defining resource/method constrains

4.2.2.1. DD

4.2.2.1.1. <web-app> .... <web-resource-collection>

4.2.2.1.2. <web-resource-collection>

4.2.2.1.3. <web-resource-name>UpdateRecipes</..

4.2.2.1.4. <url-pattern>/Beer/AddRecipe/*</... <url-pattern>/Beer/ReviewRecipe/*</...

4.2.2.1.5. <http-method>GET</... <http-method>POST</....

4.2.2.1.6. </web-resource-collection>

4.2.2.1.7. <auth-constraint> <role-name>Admin</.. <role-name>Member</.. </....

4.2.2.1.8. <user-data-constraint> <transport-guarantee>CONFIDENTIAL</... </...

4.2.2.1.9. </security-constraint> </web-app>

4.3. Multiples <security-constraint>

4.3.1. 1. when combinig individual role names, all of the roles names listed will be allowed

4.3.2. 2. A rle name of "*" combines with anything else to allow acces to everybody

4.3.3. 3. An empty <auth-constraint> tag combines with anything else to allow access to nobody, empty tag is always final word, nobody allowed

4.3.4. 4. if one <securty-constraint> has no <auth-constraint>, combines with anything else to allow access to everybody

4.4. Authentication types

4.4.1. BASIC

4.4.2. DIGEST

4.4.3. CLIENT-CERT

4.4.4. FORM

4.4.4.1. <login-config> <auth-method>FORM</.. <form-login-config> <form-login-page>/loginPage.html</.. <form-error-page>/loginError.html</.. </.... </....

4.4.4.2. action= j_security_check j_username j_password

4.5. HttpServletRequest

4.5.1. isUserInRole("roleName")

4.5.2. getRemoteUser

4.5.3. getUserPrincipal()

5. Chap 13. Wrappers and Filters

5.1. javax.servlet.Filter

5.1.1. Methods

5.1.1.1. init(FilterConfig config)

5.1.1.2. doFilter(ServletRequest, ServletResponse, FilterChain)

5.1.1.3. destroy()

5.1.2. Filters have no idea who's going to call them or who's next in line

5.2. Declaring (DD)

5.2.1. <filter> <filter-name>BeerRequest</.. <filter-class>com.example.SomeFilter</.. <init-param> <param-name>logFile</.. <param-value>Log.txt</... </init... ...

5.2.2. <filter-mapping> <filter-name>BeerRequest</.. <url-pattern>*.do</... ...

5.2.3. <filter-mapping> <filter-name>BeerRequest</.. <servlet-name>AdviceServlet</... ...

5.2.4. <dispatcher>

5.2.4.1. REQUEST, default

5.2.4.2. INCLUDE

5.2.4.3. FORWARD

5.2.4.4. ERROR

5.3. Decorator/Wrapper

5.3.1. wraps one kind of an object with an "enhanced" implementations (add new capabilities)

5.3.2. not necessary needs to override methods

5.4. Order rule

5.4.1. 1. All matching Url patterns

5.4.2. 2. Servlet-name

6. Chap 14. Patterns and Struts

6.1. Business Delegate

6.1.1. Features

6.1.1.1. Acts as a proxy, implementing the remote service's interface

6.1.1.2. initiates communications with a remote service

6.1.1.3. handles communication details and exceptions

6.1.1.4. receives request from a controller component

6.1.1.5. translates the request and forwards it to the business services

6.1.1.6. translate the response and returns it to the controller component

6.1.1.7. by handling the details of remote component lookup and communications, allows controllers to be more cohesive

6.1.2. Principales

6.1.2.1. based on

6.1.2.1.1. hiding complexity

6.1.2.1.2. coding to interfaces

6.1.2.1.3. loose copuling

6.1.2.1.4. separation of concerns

6.1.2.2. minimizes the impact on the web tier when changes occur on the buisiness tier

6.1.2.3. Reduces coupling between tiers

6.1.2.4. Adds a layer to the app, which incrases complexity

6.1.2.5. Methods calls to the Buisness Delegate should be a coarse-grained to reduce network traffic

6.2. Service Locator

6.2.1. Features

6.2.1.1. Obtains InitialContext objects

6.2.1.2. Performs registry lookups

6.2.1.3. Handles communication details and exceptions

6.2.1.4. Can improve perfomance by caching previously obtained references

6.2.1.5. Works with a variety of registries such as: JNDI, RMI, UDDI, and COSS naming

6.2.2. Principales

6.2.2.1. based on

6.2.2.1.1. hiding complexity

6.2.2.1.2. separation of concerns

6.2.2.2. minimize the impact on the web tier when remote components change locations or containers

6.2.2.3. Reduce coupling between tiers

6.3. Transfer Object

6.3.1. functions

6.3.1.1. provides a local representation of a remote entity

6.3.1.2. minimize network traffic

6.3.1.3. can follow java bean conventions so that it can be easily accessed by other objects

6.3.1.4. implemented as a serializable objects so that it can move across the network

6.3.1.5. typically easily accessible by view components

6.3.2. principales

6.3.2.1. based on reducing network traffic

6.3.2.2. minimize the performance impact on the web tier when remote components data is accessed with fine-grained calls

6.3.2.3. Reduces coupling between tiers

6.3.2.4. a drawback is that components accessing the Transfer Object can receive out-of-data data, because transfer object's data is really representing sate that's stored somewhere elese.

6.3.2.5. Making updatable transfer objects concurency-safe is typcally complex

6.4. Intercepting Filter

6.4.1. functions

6.4.1.1. can intercept and/or modify request before they reach the servlet

6.4.1.2. can intercept and/or modify the response before they are returned to the client

6.4.1.3. Filters are deployed declaratively using the DD

6.4.1.4. Filters are modular so that they can be exceuted in chains

6.4.1.5. Filters have lifecycles managed by the container

6.4.1.6. Filter must implemente Container callback methods

6.4.2. principales

6.4.2.1. based on

6.4.2.1.1. cohesion

6.4.2.1.2. lose coupling

6.4.2.1.3. increasing declarative control

6.4.2.2. delcarative control allow filters to be easily implemented on either a temporary or permanent basis

6.4.2.3. declarative control allows the sequence of invocation to be easily updated

6.5. Model View, Controller

6.5.1. features

6.5.1.1. views can change independtly from controllres and model

6.5.1.2. model components hide interal details, from the view and controllers

6.5.1.3. if the model adheres to a stric contract,then these components can be reused in other app

6.5.1.4. separation fo model code from controller code allows for easier migration to using remote buisness components

6.5.2. principales

6.5.2.1. based on

6.5.2.1.1. separation of concerns

6.5.2.1.2. loose coupling

6.5.2.2. increase cohesion in inividual components

6.5.2.3. increase the overall complexity of the application

6.5.2.4. minimize the impact of changes in other tiers of the application

6.6. Fron controller

6.6.1. features

6.6.1.1. centralize a web app's initial request handling tasks in a single component

6.6.1.2. using the fron controller with other patterns can provide loose coupling by making presentation tier dispatching declarative

6.6.1.3. a drawback of front controller is that is' very barebons compared to strus

6.6.2. principales

6.6.2.1. based on

6.6.2.1.1. hiding complexity

6.6.2.1.2. separation of concerns

6.6.2.1.3. loose coupling

6.6.2.2. increases cohesin in application controller components

6.6.2.3. decreases the overall complexity of the application

6.6.2.4. increases the maintainability of the inferastructure code

7. Chap 4. Request and Response

7.1. Container

7.1.1. Runs multiples threads to process multiple requests to a single servlet

7.1.2. Create request and response objects

7.2. Servlet's life

7.2.1. 1. Load class

7.2.2. 2. Instantiate servlet (constructor runs)

7.2.3. 3. init()

7.2.4. 4. Service()

7.2.5. 5. destroy()

7.3. Http Methods

7.3.1. GET

7.3.2. POST

7.3.3. HEAD

7.3.4. TRACE

7.3.5. PUT

7.3.6. DELETE

7.3.7. OPTIONS

7.3.8. CONNECT

7.4. Idempotent (GET, HEAD, PUT, DELETE, TRACE, OPTIONS)

7.5. Request

7.5.1. String param = request.getParameter("parameter"); request.getParameterValues("size")[0];

7.5.2. String client = request.getHeader("User-Agent"); request.getIntHeader("foo");

7.5.3. Cookie[] cookies = request.getCookies();

7.5.4. HttpSession session = request.getSession();

7.5.5. String method = request.getMethod();

7.5.6. ServletInputStream input = request.getInputSream();

7.6. Response

7.6.1. response.setContentType("application/jar");

7.6.2. PrintWriter writer = response.getWriter(); writer.println("some text and HTML");

7.6.3. ServletOutputStream out = response.getOutputStream(); out.write(aByteArray);

7.6.4. response.setHeader("foo", "bar"); response.setIntHeader("TheAnswer", 42);

7.6.5. response.addHeader("foo", "bar");

7.6.6. response.addCookie(cookie);

7.6.7. reponse.sendError(404);

7.6.8. response.sendRedirect("foo/some/pic.jpg");

7.6.9. RequestDispatcher view = request.getRequestDispatcher("foo.jsp"); view.forward(request,response);

7.7. javax.servlet.ServletRequest

7.7.1. Methods

7.7.1.1. getAttribute(String)

7.7.1.2. getContentLenght()

7.7.1.3. getinputStream()

7.7.1.4. getLocalPort()

7.7.1.5. getRemotePort()

7.7.1.6. getServerPort()

7.7.1.7. getParameter(String)

7.7.1.8. getParameterValues(String)

7.7.1.9. getParameterNames()

7.7.1.10. more..

7.7.2. father of

7.7.2.1. javax.servlet.http.HttpServletRequest

7.7.2.1.1. Methods

7.8. javax.servlet.ServletResponse

7.8.1. Methods

7.8.1.1. getBufferSize()

7.8.1.2. setContentType()

7.8.1.3. getOutputStream()

7.8.1.4. getWriter()

7.8.1.5. setContentLength()

7.8.1.6. more..

7.8.2. father of

7.8.2.1. javax.servlet.http.HttpServletResponse

7.8.2.1.1. Methods

8. Chap 5. Attributes and Listeners

8.1. Context init Parameters

8.1.1. <web-app>   <context-param>     <param-name>foo</..     <param-value>bar</...

8.1.2. getServletContext.getInintParam("foo");

8.1.3. Available to any servlet and JSP part of the web app

8.2. Servlet init Parameters

8.2.1. <servlet>   <servlet-name>     <init-param>       <param-name>foo</..       <param-value>bar</...

8.2.2. getServletConfig.getInitParam("foo");

8.2.3. Available only to the servlet for which <init-param> was configured

8.3. ServletContext

8.3.1. getInitParameter(String) : String

8.3.2. getInitParameterNames() : String[]

8.3.3. getAttribute(String) : String

8.3.4. getAttributesName() : String[]

8.3.5. setAttributes(String, Object) : void

8.3.6. removeAttribute(String) : void

8.3.7. getRequestDispatcher(String) : RequestDispatcher

8.4. Listeners

8.4.1. <listener>   <listener-class>     com.some.foor.Listener   </..

8.4.2. the AttributeEvent.getValue, holds the replaced or removed value

8.4.3. Types

8.4.3.1. javax.servlet.ServletContextListener : ServletContextEvent

8.4.3.1.1. contextInitialized

8.4.3.1.2. contextDestroyed

8.4.3.2. javax.servlet.ServletRequestListener : ServletRequestEvent

8.4.3.2.1. requestInitialized

8.4.3.2.2. requestDestroyed

8.4.3.3. javax.servlet.ServletContextAttributeListener : ServletContextAttributeEvent

8.4.3.3.1. attributeAdded

8.4.3.3.2. attributeRemoved

8.4.3.3.3. attributeReplaced

8.4.3.4. javax.servlet.ServletRequestAttributeListener : ServletRequestAttributeEvent

8.4.3.4.1. attributeAdded

8.4.3.4.2. attributeRemoved

8.4.3.4.3. attributeReplaced

8.4.3.5. javax.servlet.http.HttpSessionAttributeListener : HttpSessionBindingEvent

8.4.3.5.1. attributeAdded

8.4.3.5.2. attributeRemoved

8.4.3.5.3. attributeReplaced

8.4.3.6. javax.servlet.http.HttpSessionListener : HttpSessionEvent

8.4.3.6.1. sessionCreated

8.4.3.6.2. sessionDestroyed

8.4.3.7. javax.servlet.http.HttpSessionBindingListener : HttpSessionBindingEvent

8.4.3.7.1. valueBound

8.4.3.7.2. valueUnbound

8.4.3.8. javax.servlet.http.HttpSessionActivationListener : HttpSessionEvent

8.4.3.8.1. sessionDidActive

8.4.3.8.2. sessionWillPassivate

8.5. Attributes

8.5.1. Types

8.5.1.1. Application/context

8.5.1.2. Session

8.5.1.3. Request

8.5.2. setAttribute(String name, Object value)

8.5.3. getAtrribute(String) : Object

8.5.4. removeAttribute(String) : void

8.5.5. getAttributeNames() : Enumeration

8.6. Parameters

8.6.1. Types

8.6.1.1. Application/context init parameters

8.6.1.2. Request Paratemers

8.6.1.3. Servlet Iinit parameters

8.6.2. You CANNOT set Application and Servlet init parameters, they're set in the DD

8.6.3. getInitParameter(String) : String

8.7. RequestDispatcher

8.7.1. Methods

8.7.1.1. forward(ServletRequest, ServletResponse)

8.7.1.2. include(ServletRequest, ServletResponse)

8.7.2. RequestDispatcher view = request.getREquestDispatcher("result.jsp");

8.7.3. RequestDispatcher view = getServletContext().getRequestDispatcher("/result.jsp);

8.7.4. a flush often lead to an illegalStateException

8.7.5. getAttribute("javax.servlet.forward.query_string"); obtain the query string for the original access

8.7.6. if your servlet use an RD, it can never send its own response.

9. Chap 6. Session Managment

9.1. URL rewriting

9.1.1. Adds the session ID to the end of all URLs in the HTML that you write to the response

9.1.2. Is used to pass over the session ID when cookies are not supported but you need to explicitily encode all of the URLs you write

9.1.3. There's no way to get automatic URL rewriting with your static pages, so if you depend on sessions, you must use dynamically-generated pages

9.2. javax.servlet.http.HttpSession

9.2.1. getAttribute(String) : Object

9.2.2. getCreationTime() : long

9.2.3. getId() : String

9.2.4. getLastAcessedTime() : long

9.2.5. getMaxInactiveInterval(): int

9.2.6. getServletContext() : ServletContext

9.2.7. invalidate()

9.2.8. isNew(): boolean

9.2.9. removeAttribute(String)

9.2.10. setAttribute(String, Object)

9.2.11. setMaxInactiveInterval(int)

9.3. HttpServletRequsert

9.3.1. getSession()

9.3.2. getSession(boolean create new session if not exist)

9.4. Sessions

9.4.1. SSL has a built-in mechanism to define a session

9.4.2. URL rewriting

9.4.3. Cookies, the cookie name must be JSESSIONID

9.5. Ways a session die

9.5.1. Times out

9.5.1.1. <web-app> <session-config> <session-timeout>15</...

9.5.1.2. session.setMaxInactiveInterval(15*60);

9.5.2. invalidate()

9.5.3. App goes down

9.6. javax.servlet.http.Cookie

9.6.1. Cookie(String name, String value)

9.6.2. getDomain() : String

9.6.3. getMaxAge(): int

9.6.4. getName(): String

9.6.5. getPath() : String

9.6.6. getSecure(): boolean

9.6.7. getValue(): String

9.6.8. setDomain(String)

9.6.9. setMaxAge(int)

9.6.10. setPath(String)

9.6.11. SetValue(String)

9.7. Session Listeners

9.7.1. HttpSessionListener : HttpSessionEvent

9.7.1.1. sessionCreated

9.7.1.2. sessionDestroyed

9.7.2. HttpSessionActivationListener: HttpSessionEvent

9.7.2.1. sessionDidActive

9.7.2.2. sessionWillPassivate

9.7.3. HttpSessionBindingListener : HttpSessionBindingEvent

9.7.3.1. valueBound

9.7.3.2. valueUnbound

9.7.4. HttpSessionAttributeListener : HttpSessionBindingEvent

9.7.4.1. attributeAdded

9.7.4.2. attributeRemoved

9.7.4.3. attributeReplaced

10. Chap 7. Using JSP

10.1. Jsp

10.1.1. Import

10.1.1.1. <%@ page import="foo.*" %>

10.1.1.2. <%@ page import="foo.*,java.util.*" %>

10.1.2. Elements

10.1.2.1. <% %>

10.1.2.2. <%@ %>

10.1.2.3. <%= %>

10.1.2.4. <%! %>

10.1.3. Template text is just a fucking text =/

10.1.4. implicit objects

10.1.4.1. JspWriter : out

10.1.4.2. HttpServletRequest : request

10.1.4.3. HttpServletResponse : response

10.1.4.4. HttpSession: session

10.1.4.5. ServletContext : application

10.1.4.6. SerlvetConfig : config

10.1.4.7. Throwable : exception

10.1.4.8. PageContext : pageContext

10.1.4.9. Object : page

10.1.5. javax.servlet.jsp.JspPage

10.1.5.1. jspInit()

10.1.5.1.1. Access to

10.1.5.2. jspDestroy()

10.1.5.3. javax.servlet.jsp.HttpJspPage

10.1.5.3.1. _jspService()

10.1.6. Attributes

10.1.6.1. In a Servlet

10.1.6.1.1. Application: getServletContext().setAttribute("foo", obj);

10.1.6.1.2. Request: request.setAttribute("foo", obj);

10.1.6.1.3. Session: request.getSession().setAttribute("foo", obj);

10.1.6.1.4. Page: does not apply

10.1.6.2. In a JSP

10.1.6.2.1. Application : application.setAttribute("foo", obj)

10.1.6.2.2. Request: request.setAttribute("foo", obj)

10.1.6.2.3. Session : session.setAttribute("foo", obj)

10.1.6.2.4. Page: pageContext.setAttribute("foo", obj)

10.1.7. pageContext

10.1.7.1. Constants

10.1.7.1.1. APPLICATION_SCOPE

10.1.7.1.2. PAGE_SCOPE

10.1.7.1.3. REQUEST_SCOPE

10.1.7.1.4. SESSION_SCOPE

10.1.7.2. Methods to get any implicit object

10.1.7.2.1. getRequest()

10.1.7.2.2. getServletConfigs()

10.1.7.2.3. getServletContext()

10.1.7.2.4. getSession()

10.1.7.3. Inherited Methods from JspContext

10.1.7.3.1. getAttribute(String name)

10.1.7.3.2. getAttribute(String name, int scope)

10.1.7.3.3. getAttributeNameInScope(int scope)

10.1.7.3.4. findAttribute(String name)

10.1.8. Directives

10.1.8.1. page

10.1.8.1.1. Attributes

10.1.8.1.2. Attributes outside of the examn

10.1.8.2. taglib

10.1.8.3. include

10.1.9. Disable

10.1.9.1. scripting

10.1.9.1.1. <jsp-config> <jsp-property-group> <url-pattern>*.jsp <scriptin-invalid> true ....

10.1.9.2. EL

10.1.9.2.1. <jsp-config> <jsp-property-group> <url-patter>*.jsp.. <el-ignored> true

10.1.9.2.2. <% page isElIgnored="true">

10.1.10. Actions

10.1.10.1. Standar action : <jsp:include page="Foo.jsp"/>

10.1.10.2. Other action: <c:set var="rate" value="32" />

11. Chap 8. Scriptless JSP

11.1. EL

11.1.1. El expressions are always with curly braces, and prefixed with a dollar($) sign ${expression}

11.1.2. The first named variable in the expression is either an implicit object or an attribute in one of the four scopes (page, request, session or application)

11.1.3. The dot operator lets you access values by using a Map key or a bean property name. whatever comes to the right of the dot operator must follow normal Java naming rules

11.1.4. You can NEVER put anything to the right of the dot that wouldn't be legal as a Java identifire

11.1.5. The [] operator let you access arrays and lists

11.1.5.1. when retrive the entire list only the first element is displayed, initParam.list is the same as initParam.list[0]

11.1.6. If what's inside the brackets is not in quotes, the container evaluates it. if it's in quotes, and it's not an index into an array or list, the container sees it as the literal name of a property or key

11.1.7. All but one of the EL implicit objects are Maps (PageContext)

11.1.8. the implicit object request is represented by requestScope implicit object on EL

11.1.9. You can use TLD to call java methods

11.1.10. Alrays inside of [] should have "" if it's not a number

11.1.11. If the dot operator is used to access a bean property but the prperty doesn't exist, then a runtime exception is thrown

11.2. Bean-Related

11.2.1. <jsp:useBean>

11.2.1.1. Defines a variable that holds a reference to either an existing bean attribute or, if the bean doesn't already exist, create a new bean

11.2.1.2. MUST have an "id" attribute which declares the variable name

11.2.1.3. the "scope" attribute default is page

11.2.1.4. The "class" attribute is optional, and it declares the class type that will be used if a new bean is created. The type must be public, non-abstract and have no-args constructor

11.2.1.5. The "type" attribute must be a type to which the bean can be cast

11.2.1.6. if you have "type" attribute but not have a "class" the bean must already exist

11.2.1.7. This tag can have body, and anything in the body runs ONLY if a new bean is created

11.2.1.7.1. <jsp:setProperty>

11.3. Include

11.3.1. mechanisms

11.3.1.1. <%@ include FILE="header.html" %>

11.3.1.1.1. does the include at translation time, only once

11.3.1.2. <jsp:include PAGE="header.html" />

11.3.1.2.1. does the include at at runtime, every time!

11.3.1.2.2. can customize an included file by setting a request parameter using <jsp:param>

11.3.1.2.3. it's NOT possible to import the contents of any binary file into a JSP page

11.3.2. is position-sensitive directive

11.3.3. be sure to strip out the opening and closing tags.

11.3.4. Cannot change the response status code or set headers

11.4. Taglib declaration

11.4.1. <taglib> ... <function> <name>Some</.. <function-class>com.some.package.class</.. <function-signature>java.lang.String param (java.lang.String)</.. </... </...

11.5. <jsp:forward>

11.5.1. the response buffer is cleared first!, so anything written to the response before the forward will be thrown away

11.5.2. if you commit the response before the forwad (calling out.flush()), the forward won't happen, and the rest of the original page won't be processed

11.5.3. attribute Page