Please enable JavaScript.
Coggle requires JavaScript to display documents.
JSP (Java server pages) and servlet basics - udemy.com/jsp-servlet-free…
JSP (Java server pages) and servlet basics - udemy.com/jsp-servlet-free-course/learn/v4/overview
Install and start
Install Tomcat server in Eclipse
JDK, Tomcat e Eclipse Java EE
New project "Hello World Servlet" -> Java Resources -> SRC -> HelloWorld.java
WebContent -> Jsp or html files (jsp we can add jsp inside)
Servlets life cycle (box inside other box) =
Servlet container ->
Web app (convert jsp to servlet) ->
Servlet (
Load Servlet Class,
Create Instance of Servlet,
Call the Servlets Init() Method, The first 3 steps only runs once,
Call the Servlets Service() Method,
Call the Servlets Destroy() Method, Also the last step only runs once)
JSP Scripting Element
5 Scripting Element:---Syntax:----------------------Example:
Expression--------------<%= expression %>------<%= 2*5 %>
Scriplet-------------------<% scriptlets %>----------<% out.println("Hello World"); %>
Declaration--------------<%! declarations %>-----<%! public int count = 0; %>
Directive------------------<%@ directive %>-------<%@ page ... %>
Comment-----------------<%-- comment --%>-----<%-- JSP comment --%>
JSP Directives: <%@ Directive… %>
Page, 2. Include, 3. Taglib
(udemy.com/jsp-servlet-free-course/learn/v4/t/lecture/5377410?start=0)
Directives:
language, 2. extends, 3. import, 4. session, 5. buffer, 6. autoFlush, 7. isThreadSafe, 8. errorPage, 9. info, 10. isErrorPage, 11. contentType
Deployment descriptor and annotations
Main directory or WebContent -> WEB-INF -> web.xml
Default initial file config, servlet jsp configs and servlet mapping
Reading url parameters
request.getParameter("parameterName")
Import and Include files in JSP
Include:
<% include file="fileName.txt" %> (static content)
<jsp:include page="fileName.txt"></jsp:include> (dynamic content)
Import:
<%@ page import="java.util.Date" %> (Java class)
<%@ page import="imports.Demo" %> (Src class)
Forward and redirect under JSP
Forward:
<jsp:forward page="pageName.jsp"></jsp:forward>
(The url doesn't change, but the content yes)
request.getRequestDispatcher("pageName.jsp").forward(request, response)
(The logic is used in servlet)
Redirect:
response.sendRedirect("pageName.jsp")
JSP Implicit Objects
9 Implicit objects:-------------------Class:
out-----------------------------------javax.servlet.jsp.JspWriter
request-----------------------------javax.servlet.http.HttpServletRequest
response---------------------------javax.servlet.http.HttpServletResponse
session-----------------------------javax.servlet.http.HttpSession
application-------------------------javax.servlet.ServletContext
exception---------------------------javax.servlet.jsp.JspException
Page--------------------------------java.lang.Object
pageContext----------------------javax.servlet.jsp.PageContext
Config-------------------------------javax.servlet.ServletConfig
Forms
form under servlet -> request.getParameter() and variable.equals()
Session
usar a sessão -> session.getAtribute("variableName")
capturar a sessão -> request.getSession()