ipunit3
ipunit3
ipunit3
PROGRAMMING
UNIT 3- SERVER SIDE PROGRAMMING
1
UNIT III: SYLLABUS
• Servlets: Java Servlet Architecture - Servlet Life Cycle - Form
program example
3
SERVLETS
4
SERVLETS
• Servlet is a technology which is used to create a web application.
• Servlet is an API that provides many interfaces and classes
including documentation.
• Servlet is an interface that must be implemented for creating any
Servlet.
• Servlet is a class that extends the capabilities of the servers and
responds to the incoming requests. It can respond to any requests.
• Servlet is a web component that is deployed on the server to create
a dynamic web page.
5
SERVLETS - WORKING
6
CGI vs. SERVLETS
• What is CGI?
– Common Gateway Interface (CGI) is a standard for writing programs that
can interact through a Web server with a client running on Web browser.
7
CGI vs. SERVLETS
CGI(Common Gateway
Servlet
Interface)
Servlets can directly communicate with the CGI cannot directly communicate with the
web server. web server.
Servlets are less expensive than CGI. CGI are more expensive than Servlets.
Servlets can handle the cookies. CGI cannot handle the cookies.
8
SERVLETS - ARCHITECTURE
11
SERVLETS - LIFE CYCLE
• The web container maintains the life cycle of a servlet instance.
1. Load Servlet
• The life cycle of the servlet are as follows: Class
– Servlet Class is Loaded 2. Create
Servlet
– Servlet Instance is Created Start Instance
3. Call Init
– Init Method is Invoked Method
– Service Method is Invoked
– Destroy Method is Invoked
Ready
4. Call the
Service
Method
4. Call the
End Destroy
Method 12
SERVLETS - LIFE CYCLE
Unavailable
Un available for - Exception
Services Throw
Initialization
Failed
Destroy
Unload
13
SERVLETS - METHODS
Calls
Calls
14
SERVLETS - METHODS
• Servlet Class is Loaded
– The class loader is responsible to load the Servlet Class.
– The Servlet class is loaded when the first request for the Servlet is received
by the Web Container.
17
APCHE TOMCAT INSTALLATION
18
APCHE TOMCAT INSTALLATION
• Before start installation, need to setup JAVA_HOME or
JRE_HOME and CATALINA_HOME so that you can do
some maintenance operations on the Tomcat server like
Starting and Stopping the Server.
19
PARAMETERS, GET AND POST METHODS
• The parameters are the way in which a client or user can send
information to the Http Server.
• For example, in a login screen, we need to send to the server,
the user and the password so that it validates them.
20
PARAMETERS, GET AND POST METHODS
23
SESSION HANDLING
25
COOKIES IN SERVLET
• When next time browser sends any request to web server then
it sends those cookies information to the server and server uses
that information to identify the user. 26
TYPES OF COOKIE
27
COOKIES
Advantage of Cookies
• Simplest technique of maintaining the state.
• Cookies are maintained at client side.
Disadvantage of Cookies
• It will not work if cookie is disabled from the
browser.
• Only textual information can be set in Cookie object.
28
COOKIES
Cookie class
• javax.servlet.http.Cookie class provides the functionality of
using cookies.
How to create Cookie?
29
DATABASE CONNECTIVITY - JAVA JDBC
30
DATABASE CONNECTIVITY - JAVA JDBC
• JDBC API is a Java API that can access any kind of tabular
data, especially data stored in a Relational Database.
• JDBC works with Java on a variety of platforms, such as
Windows, Mac OS, and the various versions of UNIX.
Why Should We Use JDBC?
• Before JDBC, ODBC API was the database API to connect
and execute the query with the database.
• But, ODBC API uses ODBC driver which is written in C
language (i.e. platform dependent and unsecured).
31
JDBC VS ODBC
32
JDBC - DRIVERS
34
Native-API driver
35
Native-API driver
36
Thin driver
37
DATABASE CONNECTIVITY
38
UNDERSTANDING JSP
making use of special JSP tags, most of which start with <%
application.
39
UNDERSTANDING JSP
42
THE LIFECYCLE OF A JSP PAGE
43
THE LIFECYCLE OF A JSP PAGE
44
CREATING A SIMPLE JSP PAGE
hello.jsp
<html>
<body>
<% out.print(2*5); %>
</body>
</html>
45
JSP PROCESSING
46
JSP PROCESSING
47
JSP PROCESSING
48
JSP PROCESSING
49
JSTL
50
ADVANTAGE OF JSTL
JSP.
51