Java & JEE Training
Session 25 – Introduction to Enterprise Java; Servlets
Page 1Classification: Restricted
Agenda
• Introduction to Java EE Continued
• Servlets
Java & JEE Training
Introduction to JEE
Page 3Classification: Restricted
Web Server and Application Server
Page 4Classification: Restricted
Enterprise Java – Multi-tier architecture
Page 5Classification: Restricted
Copyright 2002 © Paulo Merson
JSP
• Used for web pages with dynamic content
• Processes HTTP requests (non-blocking call-and-return)
• Accepts HTML tags, special JSP tags, and scriptlets of Java code
• Separates static content from presentation logic
• Can be created by web designer using HTML tools
Page 6Classification: Restricted
Copyright 2002 © Paulo Merson
Servlet
• Used for web pages with dynamic content
• Processes HTTP requests (non-blocking call-and-return)
• Written in Java; uses print statements to render HTML
• Loaded into memory once and then called many times
• Provides APIs for session management
Java & JEE Training
Servlets
Page 8Classification: Restricted
What is a Servlet?
• Servlet is a technology i.e. used to create web application.
• Servlet is an API that provides many interfaces and classes including
documentations.
• Servlet is an interface that must be implemented for creating any servlet.
Page 9Classification: Restricted
How does a Servlet work?
• The web container creates threads for handling the multiple requests to the servlet.
Threads have a lot of benefits over the Processes such as they share a common
memory area, lightweight, cost of communication between the threads are low
Page 10Classification: Restricted
HTTP Response Codes
• 200 Series – OK
• 300 Series – Redirecting to another page
• 400 series – User error. E.g. 404 means page not found
• 500 series – Server error. E.g. database is down
W3C standards.
Page 11Classification: Restricted
GET vs POST
GET POST
1) In case of Get request, only limited
amount of data can be sent because data
is sent in header.
In case of post request, large amount of
data can be sent because data is sent in
body.
2) Get request is not secured because
data is exposed in URL bar.
Post request is secured because data is
not exposed in URL bar.
3) Get request can be bookmarked. Post request cannot be bookmarked.
4) Get request is idempotent . It means
second request will be ignored until
response of first request is delivered
Post request is non-idempotent.
5) Get request is more efficient and used
more than Post.
Post request is less efficient and used
less than get.
Page 12Classification: Restricted
Servlet API
• The javax.servlet package contains many interfaces and classes that are
used by the servlet or web container. These are not specific to any
protocol.
• The javax.servlet.http package contains interfaces and classes that are
responsible for http requests only.
Page 13Classification: Restricted
Life Cycle of a Servlet
• As displayed in the above diagram, there are three states of a servlet: new,
ready and end. The servlet is in new state if servlet instance is created.
After invoking the init() method, Servlet comes in the ready state. In the
ready state, servlet performs all the tasks. When the web container invokes
the destroy() method, it shifts to the end state.
Page 14Classification: Restricted
Basic Tomcat Setup
http://crunchify.com/step-by-step-guide-to-setup-and-install-apache-
tomcat-server-in-eclipse-development-environment-ide/
• Follow the steps in the link above
Page 15Classification: Restricted
Topics to be covered in next session
• HTTP Servlets and Java EE a deeper look
Page 16Classification: Restricted
Thank you!

Session 25 - Introduction to JEE, Servlets

  • 1.
    Java & JEETraining Session 25 – Introduction to Enterprise Java; Servlets
  • 2.
    Page 1Classification: Restricted Agenda •Introduction to Java EE Continued • Servlets
  • 3.
    Java & JEETraining Introduction to JEE
  • 4.
    Page 3Classification: Restricted WebServer and Application Server
  • 5.
    Page 4Classification: Restricted EnterpriseJava – Multi-tier architecture
  • 6.
    Page 5Classification: Restricted Copyright2002 © Paulo Merson JSP • Used for web pages with dynamic content • Processes HTTP requests (non-blocking call-and-return) • Accepts HTML tags, special JSP tags, and scriptlets of Java code • Separates static content from presentation logic • Can be created by web designer using HTML tools
  • 7.
    Page 6Classification: Restricted Copyright2002 © Paulo Merson Servlet • Used for web pages with dynamic content • Processes HTTP requests (non-blocking call-and-return) • Written in Java; uses print statements to render HTML • Loaded into memory once and then called many times • Provides APIs for session management
  • 8.
    Java & JEETraining Servlets
  • 9.
    Page 8Classification: Restricted Whatis a Servlet? • Servlet is a technology i.e. used to create web application. • Servlet is an API that provides many interfaces and classes including documentations. • Servlet is an interface that must be implemented for creating any servlet.
  • 10.
    Page 9Classification: Restricted Howdoes a Servlet work? • The web container creates threads for handling the multiple requests to the servlet. Threads have a lot of benefits over the Processes such as they share a common memory area, lightweight, cost of communication between the threads are low
  • 11.
    Page 10Classification: Restricted HTTPResponse Codes • 200 Series – OK • 300 Series – Redirecting to another page • 400 series – User error. E.g. 404 means page not found • 500 series – Server error. E.g. database is down W3C standards.
  • 12.
    Page 11Classification: Restricted GETvs POST GET POST 1) In case of Get request, only limited amount of data can be sent because data is sent in header. In case of post request, large amount of data can be sent because data is sent in body. 2) Get request is not secured because data is exposed in URL bar. Post request is secured because data is not exposed in URL bar. 3) Get request can be bookmarked. Post request cannot be bookmarked. 4) Get request is idempotent . It means second request will be ignored until response of first request is delivered Post request is non-idempotent. 5) Get request is more efficient and used more than Post. Post request is less efficient and used less than get.
  • 13.
    Page 12Classification: Restricted ServletAPI • The javax.servlet package contains many interfaces and classes that are used by the servlet or web container. These are not specific to any protocol. • The javax.servlet.http package contains interfaces and classes that are responsible for http requests only.
  • 14.
    Page 13Classification: Restricted LifeCycle of a Servlet • As displayed in the above diagram, there are three states of a servlet: new, ready and end. The servlet is in new state if servlet instance is created. After invoking the init() method, Servlet comes in the ready state. In the ready state, servlet performs all the tasks. When the web container invokes the destroy() method, it shifts to the end state.
  • 15.
    Page 14Classification: Restricted BasicTomcat Setup http://crunchify.com/step-by-step-guide-to-setup-and-install-apache- tomcat-server-in-eclipse-development-environment-ide/ • Follow the steps in the link above
  • 16.
    Page 15Classification: Restricted Topicsto be covered in next session • HTTP Servlets and Java EE a deeper look
  • 17.