SlideShare a Scribd company logo
Τεχνολογίες Παγκόσμιου Ιστού 
5η διάλεξη
Διαδικαστικά 
Θα ήθελα να μιλήσω με τους παρακάτω στα τελευταία 10’ του 
μαθήματος 
petros_dv, tsakatik, mirtwza, giannis156, apostoli, kir.christos, 
john_efthi, gavriili, somagion, papeslis, gi0rikas, thanoskaratzas, 
redsoukas, ntogkasxr, thomadak
Διαδικαστικά 
• Παρακαλώ δείτε τους βαθμούς της 1η εργασίας και στείλτε στον 
Έλβις τυχόν αντιρρήσεις σας 
• Η 2η εργαστηριακή άσκηση θα συζητηθεί την δεύτερη ώρα σήμερα, 
θα δωθεί αναλυτικά το απόγευμα και θα πρέπει να παραδωθεί στις 
8.00 της Δευτέρας.
Διαδικαστικά 
Σημαντική βοήθεια για την συνέχεια του μαθήματος και ιδιαίτερα στο 
θέμα των εργασιών θα βρείτε στα 
http://stackoverflow.com 
http://www.roseindia.net
2η εργασία 
• Μελέτησε το 4ο κεφάλαιο και προπάθησε το αντίστοιχο τεστ. 
• Ξεκίνα την εξοικοίωσή σου με το https://netbeans.org 
• Εγκατέστησε στο VM σου στον Ωκεανό 
• LAMP 
• http://tomcat.apache.org 
• Wordpress
LAMP
Being a Servlet 
Chapter 4
From HMTL to 
servlet class
What else?
Be carefull!! 
getServerPort(), getLocalPort() & getRemotePort()
Response now 
Use the response for I/O when 
• There is no JSP 
• No JSP is allowed 
• Do not want to use JSP 
• Do not send HTML
Παράδειγμα
Redirect 
sendRedirect() method: 
if (worksForMe) { 
// handle the request 
} else { 
response.sendRedirect(“http://www.oreilly.com”); 
} 
Redirect is not dispatch
Being a Web Application 
Chapter 5
Protecting my e-mail address 
PrintWriter out = response.getWriter(); 
out.println(“mav@uth.gr”); 
<servlet> 
<servlet-name>BeerParamTests</servlet-name> 
<servlet-class>TestInitParams</servlet-class> 
<init-param> 
<param-name>adminEmail</param-name> 
<param-value>mav@uth.gr</param-value> 
</init-param> 
</servlet> 
out.println(getServletConfig().getInitParameter(“adminEmail”));
Servlet initializations and ServletConfig 
The Container (after running the constructor) 
• Creates a unique ServletConfig 
• Reads servlet init parameters 
• Gives them to ServletConfig 
• Passes ServletConfig to servlet’s init() method
Δηλαδή
Testing Servlet Config
Re-deploying a servlet 
• Edit DD 
• Shut and restart the container 
• You better be careful what you put as init-param
Give JSP servlet’s init params 
• As a request attribute
Give JSP servlet’s init params 
• Using Context
Context & 
Servlet init 
parameters
Context & Servlet init parameters 
Container 
• Reads DD and creates name/ 
value string pairs for each 
<context-param> 
• Creates a new instance of 
ServletContext 
• Passes (as reference) pairs to 
ServletContext 
JSP is a servlet
What else is in 
ServletContext?
We need a listener 
Which 
Listens for context initialization events 
Runs specific code before servlet starts serving 
Notice, there is no main()!
ServletContextListener
Make and use a context listener 
Create a listener class 
Put the class in WEB-INF/classes 
Put <listener> element in DD 
• Three classes (and one DD) 
ServletContextListener.java 
Dog.java 
ListenerTester.java
Listener 
class
Attribute class 
Context init parameters as the 
argument for the constructor 
servlet will 
get dog from context 
call getBreed() 
print the value of breed
Servlet class
The DD 
(web.xml in 
WEB-INF)
Compile and Deploy 
Compile the three classes 
Create a new web app in Tomcat 
Create ListenerTest and WEB-INF 
Put web.xml in WEB-INF 
Make a classes directory underneath. 
Create a directory structure that matches your package 
structure 
Put web.xml and the three compiled files into their space 
Shutdown and restart Tomcat
The whole story
Ch5   beeing an application
Context 
& 
Servlet 
init 
parameters
Context 
& 
Servlet 
init 
parameters 
Container 
• Reads 
DD 
and 
creates 
name/value 
string 
pairs 
for 
each 
<context-­‐param> 
• Creates 
a 
new 
instance 
of 
ServletContext 
• Passes 
(as 
reference) 
pairs 
to 
ServletContext
What 
else 
is 
in 
ServletContext? 
You 
may 
get 
them 
but 
NOT 
set 
them 
later
Initializing 
your 
web 
application 
with 
an 
object 
After 
initializing 
with 
a 
string 
of 
course
We 
need 
a 
listener 
(a 
Java 
object) 
• That 
– Listens 
for 
context 
initialization 
events 
– Runs 
specific 
code 
before 
servlet 
starts 
serving 
Notice! 
There 
is 
no 
main()
ServletContextListener
Listen 
to 
the 
Dog
Make 
and 
use 
a 
context 
listener 
• Create 
a 
listener 
class 
• Put 
the 
class 
in 
WEB-­‐INF/classes 
• Put 
<listener> 
element 
in 
DD 
• Three 
classes 
(and 
one 
DD) 
– ServletContextListener.java 
– Dog.java 
– ListenerTester.java
Listener 
class
Attribute 
class
Servlet 
class
The 
DD 
(the 
web.xml 
in 
WEB-­‐INF)
Review
The 
whole 
story 
(In 
pictures)
You 
can 
listen 
all 
kinds 
of 
events
Attributes 
• Who 
can 
put 
(and 
remove)? 
• Who 
can 
see? 
• For 
how 
long? 
SCOPE
Attributes 
are 
not 
Parameters!
The 
3 
Scopes
The 
3 
Scopes 
(API)
Beware 
of 
Attributes 
(1/2)
Beware 
of 
Attributes 
(2/2)
Thread-­‐Safe 
Context 
Attributes
Ch5   beeing an application
Lock 
the 
Context 
(not 
the 
Service)
Thread-­‐Safe 
Session 
Attributes
SingleThreadModel 
No 
two 
threats 
will 
execute 
concurrently 
in 
the 
servlet’s 
service 
method. 
Two 
choices 
for 
STM 
implementation
Only 
request 
attributes 
and 
local 
variables 
are 
thread-­‐safe 
• Instance 
variables 
aren’t 
thread-­‐safe 
• Classes 
aren’t 
thread-­‐safe
Request 
attributes 
& 
Request 
dispatching
What 
is 
wrong 
here?

More Related Content

PDF
4η διάλεξη Τεχνολογίες Παγκόσμιου Ιστού
PDF
Being a jsp
PDF
Ch. 7 beeing a jsp
PDF
Ch. 11 deploying
PDF
Ch. 13 filters and wrappers
PDF
Ch. 8 script free pages
PPTX
Advance java session 15
PPTX
Advance java session 20
4η διάλεξη Τεχνολογίες Παγκόσμιου Ιστού
Being a jsp
Ch. 7 beeing a jsp
Ch. 11 deploying
Ch. 13 filters and wrappers
Ch. 8 script free pages
Advance java session 15
Advance java session 20

What's hot (20)

PPTX
Wt unit 4
PPTX
Wt unit 3
PPTX
Node.js
PPTX
SenchaCon 2016: Learn the Top 10 Best ES2015 Features - Lee Boonstra
PDF
Shootout! template engines on the jvm
PPTX
Alfresco Mvc - a seamless integration with Spring Mvc
PPT
Node.js Express Framework
PDF
Introduction to Laravel
PDF
Your First Scala Web Application using Play 2.1
PPT
Node js Modules and Event Emitters
PDF
Django rest framework tips and tricks
PPT
MuleSoft ESB Object Store
PPTX
Laravel Webcon 2015
PDF
PPTX
Core web application development
PPTX
Advance java session 9
PPTX
Building Apis in Scala with Playframework2
PDF
MuleSoft ESB Shared Library
PPTX
MuleSoft ESB Payload Encrypt using Anypoint Security
PPTX
Puppet Fundamentals Talk at DevOps Dubai by Hameedullah Khan
Wt unit 4
Wt unit 3
Node.js
SenchaCon 2016: Learn the Top 10 Best ES2015 Features - Lee Boonstra
Shootout! template engines on the jvm
Alfresco Mvc - a seamless integration with Spring Mvc
Node.js Express Framework
Introduction to Laravel
Your First Scala Web Application using Play 2.1
Node js Modules and Event Emitters
Django rest framework tips and tricks
MuleSoft ESB Object Store
Laravel Webcon 2015
Core web application development
Advance java session 9
Building Apis in Scala with Playframework2
MuleSoft ESB Shared Library
MuleSoft ESB Payload Encrypt using Anypoint Security
Puppet Fundamentals Talk at DevOps Dubai by Hameedullah Khan
Ad

Viewers also liked (9)

PDF
Ch6 conversational state
PDF
3η διάλεξη Τεχνολογίες Παγκόσμιου Ιστού
PDF
Ch. x web performance
PDF
Ch. 12 security
PDF
1η διάλεξη Τεχνολογίες Παγκόσμιου Ιστού
PDF
2η διάλεξη Τεχνολογίες Παγκόσμιου Ιστού
PDF
Ch. 10 custom tag development
PDF
Ch. 9 jsp standard tag library
PDF
Study: The Future of VR, AR and Self-Driving Cars
Ch6 conversational state
3η διάλεξη Τεχνολογίες Παγκόσμιου Ιστού
Ch. x web performance
Ch. 12 security
1η διάλεξη Τεχνολογίες Παγκόσμιου Ιστού
2η διάλεξη Τεχνολογίες Παγκόσμιου Ιστού
Ch. 10 custom tag development
Ch. 9 jsp standard tag library
Study: The Future of VR, AR and Self-Driving Cars
Ad

Similar to Ch5 beeing an application (20)

PPT
PPT
Module 4.pptModule 4.pptModule 4.pptModule 4.ppt
PPT
JAVA Servlets
PDF
4_598113hhhhhhhhhhhhhhhhhhhhhhh0134529250346.pdf
PPTX
J2EE : Java servlet and its types, environment
PDF
Lecture: "Advanced Reflection: MetaLinks"
PPTX
Integrating Servlets and JSP (The MVC Architecture)
PDF
Servlet and JSP
PDF
Java Servlets.pdf
PDF
Lecture. Advanced Reflection: MetaLinks
PDF
Java Servlet Programming under Ubuntu Linux by Tushar B Kute
PDF
Variables in Pharo
PDF
VUB Brussels Lecture 2019: Advanced Reflection: MetaLinks
PPTX
servlets sessions and cookies, jdbc connectivity
PDF
06 response-headers
PPT
Java Servlet
PPTX
ajava unit 1.pptx
PDF
Adv java unit 4 M.Sc CS.pdf
PPTX
Enterprise java unit-1_chapter-3
Module 4.pptModule 4.pptModule 4.pptModule 4.ppt
JAVA Servlets
4_598113hhhhhhhhhhhhhhhhhhhhhhh0134529250346.pdf
J2EE : Java servlet and its types, environment
Lecture: "Advanced Reflection: MetaLinks"
Integrating Servlets and JSP (The MVC Architecture)
Servlet and JSP
Java Servlets.pdf
Lecture. Advanced Reflection: MetaLinks
Java Servlet Programming under Ubuntu Linux by Tushar B Kute
Variables in Pharo
VUB Brussels Lecture 2019: Advanced Reflection: MetaLinks
servlets sessions and cookies, jdbc connectivity
06 response-headers
Java Servlet
ajava unit 1.pptx
Adv java unit 4 M.Sc CS.pdf
Enterprise java unit-1_chapter-3

Recently uploaded (20)

PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PPTX
PPH.pptx obstetrics and gynecology in nursing
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PDF
Basic Mud Logging Guide for educational purpose
PPTX
Institutional Correction lecture only . . .
PDF
Business Ethics Teaching Materials for college
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PDF
O7-L3 Supply Chain Operations - ICLT Program
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PDF
Complications of Minimal Access Surgery at WLH
PDF
Anesthesia in Laparoscopic Surgery in India
PPTX
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
Insiders guide to clinical Medicine.pdf
PPTX
master seminar digital applications in india
PPTX
Cell Structure & Organelles in detailed.
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PDF
VCE English Exam - Section C Student Revision Booklet
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PPH.pptx obstetrics and gynecology in nursing
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
Basic Mud Logging Guide for educational purpose
Institutional Correction lecture only . . .
Business Ethics Teaching Materials for college
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
O7-L3 Supply Chain Operations - ICLT Program
Abdominal Access Techniques with Prof. Dr. R K Mishra
102 student loan defaulters named and shamed – Is someone you know on the list?
Complications of Minimal Access Surgery at WLH
Anesthesia in Laparoscopic Surgery in India
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
Insiders guide to clinical Medicine.pdf
master seminar digital applications in india
Cell Structure & Organelles in detailed.
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
VCE English Exam - Section C Student Revision Booklet

Ch5 beeing an application