Java Servlet Presentation
Java Servlet Presentation
Softsmith Infotech
Servers
Typically, your little computer is the client, and someone elses big
computer is the server
However, any computer can be a server
It is not unusual to have server software and client software
running on the same computer
Softsmith Infotech
Apache
Apache is:
Full-featured and extensible
Efficient
Robust
Secure (at least, more secure than other servers)
Up to date with current standards
Open source
Free
Why use anything else?
Softsmith Infotech
Ports
Softsmith Infotech
Ports II
But it is also:
http:// www.softsmith.com:80 /~servlet
Softsmith Infotech
CGI Scripts
client
client
server
script
Softsmith Infotech
Servlets
client
client
server
servlet
Softsmith Infotech
Advantages:
Running a servlet doesnt require creating a separate process
each time
A servlet stays in memory, so it doesnt have to be reloaded
each time
There is only one instance handling multiple requests, not a
separate instance for every request
Untrusted servlets can be run in a sandbox
Disadvantage:
Less choice of languages (CGI scripts can be in any language)
Softsmith Infotech
Servlets
Softsmith Infotech
Softsmith Infotech
10
HTTP requests
Softsmith Infotech
11
Softsmith Infotech
12
13
The superclass
public class HelloServlet extends HttpServlet {
Every class must extend GenericServlet or a subclass of
GenericServlet
GenericServlet is protocol independent, so you could write
a servlet to process any protocol
In practice, you almost always want to respond to an HTTP
request, so you extend HttpServlet
A subclass of HttpServlet must override at least one method,
usually one doGet, doPost, doPut, doDelete, init and destroy, or
getServletInfo
Softsmith Infotech
14
Softsmith Infotech
15
Parameters to doGet
I/O in Java is very flexible but also quite complex, so this object
acts as an assistant
Softsmith Infotech
16
Softsmith Infotech
17
Softsmith Infotech
18
Input to a servlet
Softsmith Infotech
19
Softsmith Infotech
20
Enumeration review
Example use:
Enumeration e = myVector.elements();
while (e.hasMoreElements()) {
System.out.println(e.nextElement());
}
Softsmith Infotech
21
Softsmith Infotech
22
Softsmith Infotech
23
Session Tracking
What is Session?
A Session refers to all the request that a single client makes to a
server.
Every user has a separate session and separate session variable is
associated with that session.
A session is specific to the user and for each user a new session is
created to track all the request from that user.
Softsmith Infotech
24
Softsmith Infotech
25
HttpSession.
Cookies.
URL rewriting .
Hidden form fields.
Softsmith Infotech
26