of 62
7/29/2019 servlet basic
1/62
Introduction to the Semantic Web Tutorial
CNPM CNTT - KHTN
SERVLET BASICS
Ging vin: Nguyn Hong Anh
Email: [email protected]
7/29/2019 servlet basic
2/62
Introduction to the Semantic Web Tutorial
CNPM CNTT - KHTN
Bi gingc trch t
http://www.javapassion.com/j2ee/
http://courses.coreservlets.com/Course-
Materials/csajsp2.html
http://www.javapassion.com/j2ee/http://courses.coreservlets.com/Course-Materials/csajsp2.htmlhttp://courses.coreservlets.com/Course-Materials/csajsp2.htmlhttp://courses.coreservlets.com/Course-Materials/csajsp2.htmlhttp://courses.coreservlets.com/Course-Materials/csajsp2.htmlhttp://courses.coreservlets.com/Course-Materials/csajsp2.htmlhttp://courses.coreservlets.com/Course-Materials/csajsp2.htmlhttp://www.javapassion.com/j2ee/7/29/2019 servlet basic
3/62
Introduction to the Semantic Web Tutorial
CNPM CNTT - KHTN
Contents
1 Servlet
2 Servlet Request & Response
3 Servlet Life Cycle
4 Scope Object
7/29/2019 servlet basic
4/62
Introduction to the Semantic Web Tutorial
CNPM CNTT - KHTN
J2EE Architecture (1.2)
7/29/2019 servlet basic
5/62
Introduction to the Semantic Web Tutorial
CNPM CNTT - KHTN
Servlet
Client SidePresentation
HTML
Java Applet
JavaApplication
Server SidePresentation
SERVLET
JSP
DatabaseAccess
JDBC
HIBERNATE
EJB,
DBMS
SQL Server
MySQL
DB2,
7/29/2019 servlet basic
6/62
Introduction to the Semantic Web Tutorial
CNPM CNTT - KHTN
Servlet Code
7/29/2019 servlet basic
7/62Introduction to the Semantic Web TutorialCNPM CNTT - KHTN
Servlet Request & Response
7/29/2019 servlet basic
8/62Introduction to the Semantic Web TutorialCNPM CNTT - KHTN
Request & Response
7/29/2019 servlet basic
9/62Introduction to the Semantic Web TutorialCNPM CNTT - KHTN
HTTP GET & HTTP POST
7/29/2019 servlet basic
10/62Introduction to the Semantic Web TutorialCNPM CNTT - KHTN
First Servlet
7/29/2019 servlet basic
11/62Introduction to the Semantic Web TutorialCNPM CNTT - KHTN
Servlet Interfaces & Classes
7/29/2019 servlet basic
12/62Introduction to the Semantic Web TutorialCNPM CNTT - KHTN
Servlet Life-Cycle
7/29/2019 servlet basic
13/62
Introduction to the Semantic Web TutorialCNPM CNTT - KHTN
Servlet Life-Cycle Methods
7/29/2019 servlet basic
14/62
Introduction to the Semantic Web TutorialCNPM CNTT - KHTN
Servlet Life-Cycle Methods
7/29/2019 servlet basic
15/62
Introduction to the Semantic Web TutorialCNPM CNTT - KHTN
Servlet Life-Cycle Methods
7/29/2019 servlet basic
16/62
Introduction to the Semantic Web TutorialCNPM CNTT - KHTN
init() from CatalogServlet.java
7/29/2019 servlet basic
17/62
Introduction to the Semantic Web TutorialCNPM CNTT - KHTN
init() reading Configuration parameters
7/29/2019 servlet basic
18/62
Introduction to the Semantic Web TutorialCNPM CNTT - KHTN
Setting Init Parameters in web.xml
7/29/2019 servlet basic
19/62
Introduction to the Semantic Web TutorialCNPM CNTT - KHTN
destroy
7/29/2019 servlet basic
20/62
Introduction to the Semantic Web TutorialCNPM CNTT - KHTN
Servlet Life-Cycle Methods
7/29/2019 servlet basic
21/62
Introduction to the Semantic Web TutorialCNPM CNTT - KHTN
service & doGet , doPost
7/29/2019 servlet basic
22/62
Introduction to the Semantic Web TutorialCNPM CNTT - KHTN
Service()
7/29/2019 servlet basic
23/62
Introduction to the Semantic Web TutorialCNPM CNTT - KHTN
doGet() & doPost()
7/29/2019 servlet basic
24/62
Introduction to the Semantic Web TutorialCNPM CNTT - KHTN
doGet()
7/29/2019 servlet basic
25/62
Introduction to the Semantic Web TutorialCNPM CNTT - KHTN
doGet()
7/29/2019 servlet basic
26/62
Introduction to the Semantic Web TutorialCNPM CNTT - KHTN
doGet()
7/29/2019 servlet basic
27/62
Introduction to the Semantic Web TutorialCNPM CNTT - KHTN
Steps of Populating HTTP Response
7/29/2019 servlet basic
28/62
Introduction to the Semantic Web TutorialCNPM CNTT - KHTN
Response
7/29/2019 servlet basic
29/62
Introduction to the Semantic Web TutorialCNPM CNTT - KHTN
Scope Objects
7/29/2019 servlet basic
30/62
Introduction to the Semantic Web TutorialCNPM CNTT - KHTN
Four Scope Objects: Accessibility
7/29/2019 servlet basic
31/62
Introduction to the Semantic Web TutorialCNPM CNTT - KHTN
Four Scope Objects: Class
7/29/2019 servlet basic
32/62
Introduction to the Semantic Web TutorialCNPM CNTT - KHTN
Scope Objects
7/29/2019 servlet basic
33/62
Introduction to the Semantic Web TutorialCNPM CNTT - KHTN
What is ServletContext For?
7/29/2019 servlet basic
34/62
Introduction to the Semantic Web TutorialCNPM CNTT - KHTN
Scope of ServletContext
ServletContext:
7/29/2019 servlet basic
35/62
Introduction to the Semantic Web TutorialCNPM CNTT - KHTN
ServletContext:
Web Application Scope
How to Access ServletContext
7/29/2019 servlet basic
36/62
Introduction to the Semantic Web TutorialCNPM CNTT - KHTN
How to Access ServletContext
Object?
Example: Getting Attribute
7/29/2019 servlet basic
37/62
Introduction to the Semantic Web TutorialCNPM CNTT - KHTN
Example: Getting Attribute
Value from ServletContext
Example: Getting and Using
7/29/2019 servlet basic
38/62
Introduction to the Semantic Web TutorialCNPM CNTT - KHTN
Example: Getting and Using
RequestDispatcher Object
7/29/2019 servlet basic
39/62
Introduction to the Semantic Web TutorialCNPM CNTT - KHTN
Example: Logging
7/29/2019 servlet basic
40/62
Introduction to the Semantic Web TutorialCNPM CNTT - KHTN
Why HttpSession?
7/29/2019 servlet basic
41/62
7/29/2019 servlet basic
42/62
Introduction to the Semantic Web TutorialCNPM CNTT - KHTN
Example: HttpSession
7/29/2019 servlet basic
43/62
Introduction to the Semantic Web TutorialCNPM CNTT - KHTN
What is Servlet Request?
7/29/2019 servlet basic
44/62
Introduction to the Semantic Web TutorialCNPM CNTT - KHTN
Session
7/29/2019 servlet basic
45/62
Introduction to the Semantic Web TutorialCNPM CNTT - KHTN
Request
7/29/2019 servlet basic
46/62
Introduction to the Semantic Web TutorialCNPM CNTT - KHTN
Getting Client Sent Parameters
7/29/2019 servlet basic
47/62
Introduction to the Semantic Web TutorialCNPM CNTT - KHTN
A Sample FORM using GET
7/29/2019 servlet basic
48/62
Introduction to the Semantic Web TutorialCNPM CNTT - KHTN
A Sample FORM using GET
7/29/2019 servlet basic
49/62
Introduction to the Semantic Web TutorialCNPM CNTT - KHTN
A FORM Based Servlet: Get
7/29/2019 servlet basic
50/62
Introduction to the Semantic Web TutorialCNPM CNTT - KHTN
A Sample FORM using POST
7/29/2019 servlet basic
51/62
Introduction to the Semantic Web TutorialCNPM CNTT - KHTN
A Sample FORM using POST
7/29/2019 servlet basic
52/62
Introduction to the Semantic Web TutorialCNPM CNTT - KHTN
A Form Based Servlet: POST
7/29/2019 servlet basic
53/62
Introduction to the Semantic Web TutorialCNPM CNTT - KHTN
What is HTTP Servlet Request?
7/29/2019 servlet basic
54/62
Introduction to the Semantic Web TutorialCNPM CNTT - KHTN
HTTP Request URL
7/29/2019 servlet basic
55/62
Introduction to the Semantic Web TutorialCNPM CNTT - KHTN
HTTP Request URL:[requestpath]
7/29/2019 servlet basic
56/62
Introduction to the Semantic Web TutorialCNPM CNTT - KHTN
HTTP Request URL: [query string]
C t t P th Q P t
7/29/2019 servlet basic
57/62
Introduction to the Semantic Web TutorialCNPM CNTT - KHTN
Context, Path, Query, Parameter
Cookie Method
7/29/2019 servlet basic
58/62
Introduction to the Semantic Web TutorialCNPM CNTT - KHTN
Cookie Method
(in HTTPServletRequest)
P R t
7/29/2019 servlet basic
59/62
Introduction to the Semantic Web TutorialCNPM CNTT - KHTN
Page, Request
Wh t i S l t R ?
7/29/2019 servlet basic
60/62
Introduction to the Semantic Web TutorialCNPM CNTT - KHTN
What is Servlet Response?
R
7/29/2019 servlet basic
61/62
Introduction to the Semantic Web TutorialCNPM CNTT - KHTN
Responses
R St t
7/29/2019 servlet basic
62/62
Response Structure