Mapa mental
Java Web

Conteúdo do mapa
Java Web
web application
- deployable unit of content and configuration
deployment
- 2 ways
- copying files
- deploy war
- 2 ways
Servlet
- must implement servlet interface
- protocol agnostic (can use others tha HTTP)
- Generic servlet class
- HttpServlet class
- contains
- a request obj
- a response obj
- service method
- 4 http methods
- get response object as param
- response can redirect
- return string
- return component
- get request as param
- get headers, parameter, body for POST etc
- get response object as param
- init method
- contains
- HttpServlet class
- servlet mapping(rounting)
- notation @WebServlet("/home")
- also can use @WebServlet(urlPatterns = {"", "*.something"})
- mapping info held in web.xml
- define 2 sections
- servlet
- creates a servlet and associated to a class
- servlet mapping
- bind an URL or URL patter to an existing servlet
- servlet
- define 2 sections
- try not to mix both approches
- notation @WebServlet("/home")
- Initialization
- override init method from generic servlet
- use annotation
- initParams = {@WebInitParam (name="", value="")}
- override in web.xml
- define values in xml, and bind in init()
- use annotation
- override init method from generic servlet
- ServletContext
- container context app wide scope
- all servlet in container have access
- in order to used
- define in web.xml a "context-param" tag
- container context app wide scope
- RequestDispatcher
- a servlet catch request
- then use request dispatcher to send it into other Servlet or JSP
- Accessible from Servlet Context
- RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/index.jsp")
- use 1 of 3 methods available to pass beans
- dispatchet.forward(request, response)
- use 1 of 3 methods available to pass beans
- RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/index.jsp")
- a servlet catch request
- must implement servlet interface
Java Server Pages
- contain multiple lenguages
- HTML
- to define component
- java
- to define behavior
- wrap it inside <% ... %>
- HTML
- is compiled
- into a servlet(index_jsp.java)
- extend HttpJspBase which
- extends HttpServlet
- here, HTML is replaced by its java counterpart
- extend HttpJspBase which
- page translation time
- when JSP is translated into java
- and java is compiled into class file
- when JSP is translated into java
- into a servlet(index_jsp.java)
- life cycle (same as servlet)
- init()
- Destroy
- Service
- directives
- include
- <%@include file="" %>
- used as a reference to add a splitted html fragment
- <%@include file="" %>
- <%@page..."%>
- to modify page behavior
- <%@page autoFlush="" "%>
- <%@page errorPage="" "%>
- <%@page buffer="8kb" "%>
- <%@page isErrorPage="true" "%>
- give us access to exception element
- <%= exception.getMessage() %> and more error info avai.
- give us access to exception element
- to modify page behavior
- define behavior on run time of the page
- include
- handling exception
- define in web.xml an <error-page> specifing the JSP path
- throw new exception
- define in web.xml an <error-page> specifing the JSP path
- implicit objects
- request
- response
- objects created by the web container for each jsp page
- contain multiple lenguages
MVC
- Model = POJO or Beans
- May contain logic or just data
- should be stored in a context to access it
- globally so any JSP can access it
- getServletContext().setAttribute(name, object);
- inside a session so only an specific user has access
- request.getSession.setAttribute("user", user)
- passed through Request Dispatcher
- request.setAttribute("user", user)
- globally so any JSP can access it
- properties accessibility
- dot object.property
- [] : object["property"]
- Controller = Servlet or Listeners
- View = JSP
- Model = POJO or Beans
expression language
- language simpler than java tag
- used inside html tag
- ${user.name}
- could be used to replace java code tags
- used inside html tag
- not need to specify scope
- it look in all scopes for the object
- can use this technique to assing dinamically styles
- has access to implicit objects
- it look in all scopes for the object
- operators
- mathematical
- logical
- empty
- validate the value of a var
- language simpler than java tag
Java Standard Tag Library
- provide encapsulation of UI logic
- set of standard tags used in JSP
- individual tags are java classes
- tag metadata held in Tag Library Descriptor file
- wrapped inside a JAR
- in order to use it, need to import the tag core
- <% taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
- then can use it throug: <c::tag_name value="" >
- <% taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
- core tag
- conditional tags
- formatting tags
- SQL tags
- can use Exp language to validate conditions
Imagens e arquivos do mapa
Informações
- Descrição
- Mapa Mental sobre Java Web, criado por Jorge Celis em 25-09-2019.
- Criado por
- Jorge Celis
- Visualizações
- 0
- Avaliação
