SlideShare una empresa de Scribd logo
1 de 53
 To create a simple HTTP server in Java
 To use the implementation to illustrate a
number of advanced Java features:
› TCP/IP Sockets and Server Sockets
› Interfaces
› Software components (more from John later)
› Multithreading
 To show how to create executable
server objects (using Sun’s Servlets API)
 Java Network Programming, Elliotte
Rusty Harold, O’Reilly and Associates,
1997, ISBN 1-56592-227-1
 TCP/IP Network Administration, Second
Edition, Craig Hunt, O’Reilly and
Associates, 1997, ISBN 1-56592-322-7
 The Java Developer’s connection:
http://www.javasoft.com/jdc
 The Javadoc documentation
 Server must be able to process HTTP/1.0
file transfer requests and deliver files
 Connections are to be made via TCP/IP
 Must be efficient and prompt
 Must be simple to understand and
elegant in design
 Developed by Tim Berners-Lee at CERN
 Like most Internet protocols it is
described in an RFC (Request for
Comment document): RFC1945
 May be downloaded from the Internet
Engineering Task Force’s web site:
http://www.ietf.org
 Some of you may have covered this in
the introductory Java course
 Servers have a listener loop
› Loop until the server is shutdown
 Wait for a client to request a connection
 Read the details of the client’s request
 Provide the requested information to the client
 Here’s the listener loop from our
example:
ServerSocket socket = new ServerSocket(80, 5);
public void listen()
throws IllegalAccessException,
InstantiationException,
IOException
{
for (;;) {
System.err.println("HttpServer: waiting...");
Socket s = socket.accept();
FileServer f = createFileServer();
f.dispatch(s);
}
}
2037 80
2037 1583
2037 1583
Client (sid) Server (fred)
ServerSocket ss.
s = ss.accept()
s = new Socket
(“fred”, 80)
Socket s
s.getInputStream()
s.getOuputStream()
s.getInputStream()
s.getOuputStream()
 Good software is designed in a modular
fashion avoiding stovepipe designs!
 This is a form of software components
 Java has strong support for components
 Components hide their implementation
behind interfaces
 An interface defines a contract between
the supplier/server and the user/client.
ServerSocket socket = new ServerSocket(80, 5);
public void listen()
throws IllegalAccessException,
InstantiationException,
IOException
{
for (;;) {
System.err.println("HttpServer: waiting...");
Socket s = socket.accept();
FileServer f = createFileServer();
f.dispatch(s);
}
}
 Simplifies client implementation
 Clients do not need to worry about the
implementation details
 Interfaces encapsulate state of different
subsystems ⇒ side effects reduced
 Define clear boundaries between different
teams of programmers
 Clients can substitute alternative
implementations: polymorphism
 Clients can purchase off the shelf solutions:
software components
Software Component
Client Program
Interface /ublic class HttpServer
{
/**
Listens indefinitely for transfer requests and creates a server
instance for each request.
*/
public void listen()
throws IllegalAccessException, InstantiationException, IOException
{
for (;;) {
/*
Block, waiting for a request to occur then spawns a new
(anonymous) socket with which to deal with the request.
*/
System.err.println("HttpServer: waiting...");
Socket s = socket.accept();
/*
Create a file server to deal with the new socket.
*/
FileServer f = createFileServer();
f.dispatch(s);
}
}
public static void main(String[] args)
{
try {
HttpServer htts = new HttpServer("sea.server.ThreadedFileServer");
htts.listen();
}
catch (Exception e) {
System.err.println("HttpServer: failed due to exception:n" + e);
}
}
public interface FileServer
{
/**
This method allows an incoming HTTP request to initiate a
file dispatch. The socket will provide an input stream (which
is at the beginning) from which an HTTP/1.0 header request may
be read.<p>
It also provides an output stream on which the request should be
delivered. The delivery should have an HTTP/1.0 header
prepended.
@param s The socket on which a request is being made.
Once this method has returned the socket will have
been closed by the dispatcher.
*/
public void dispatch(Socket s);
}
 Each interface is a contract between
two parties
 The contract should be made as strict
and precise as possible
 Avoid unnecessary ambiguity
 Document the contract within the
interface’s source file using Javadoc
 Two flavours of FileServer have been
provided using deferred instantiation
› A simple one but with low performance:
sea.server.SimpleFileServer
› A server that uses multiple threads to
increase performance:
sea.server.ThreadedFileServer
› A server which uses a pool of threads to
achieve the maximum possible
performance: sea.server.ThreadedServer2
 Must implement the FileServer interface
so that it can plug in to the HttpServer
 Reads the HTTP request from the Socket’s
input stream
 Decides which file is required
 Reads the file and spools to the Socket’s
output stream.
public class SimpleFileServer implements FileServer
{
protected Socket s = null;
public void dispatch(Socket s)
{
this.s = s;
respond();
}
. . . .
}
 Must get an input stream so that we
can analyse the request
 Socket provides the method
› InputStream getInputStream();
Socket s;
InputStream inStream = s.getInputStream();
InputStreamReader reader = new InputStreamReader(inStream);
BufferedReader input = new BufferedReader(reader);
 Request consists of a number of lines of
text separated by “rn”
 First line is all this server is interested in
 A typical request might be of the form:
GET /path/to/file.html HTTP/1.0
Accept: text/html
Accept: image/gif
User-Agent: Lynx/2.4
 Cuts out the file name
 Looks for the file relative to the current
working directory (not portable!!)
 If the file is a directory look for the file
“index.html” in the directory
 If the file does not exist then respond with
an error (code 404)
 Must construct a header for the response
 Code 200 means success
 Simple header takes the following form:
HTTP/1.0 200 OK
Server: SEA/1.0
MIME-version: 1.0
Content-type: text/html
Data starts after blank line. . .
More data, etc. . .
 Get the output stream from the Socket
› OutputStream getOutputStream()
 Spool (copy) the file contents into the
socket
 If the MIME type is textual then we must
make sure the lines are delimited by
“rn”.
 Otherwise we pass the file unmodified
 The SimpleFileServer is completely
sequential.
› It handles one request at a time.
 Reading a file from disk takes a long time
(around 10ms)
 The server will be sitting idle while it waits
for the file to load (wasting up to 106
instruction cycles)
 Other web browsers will be kept waiting
Start HTTP request loading
Block awaiting disk availability
Deliver web page across network
time
 Threaded servers can process several
requests at once. Each request is
handled by a separate thread.
 This doesn’t increase the overall amount
of work done (unless using SMP)
 . . . but it does reduce the wastage!
 Threaded operation is worthwhile when
threads are expected to block, awaiting
I/O operations
Start HTTP request loading
Block awaiting disk availability
Deliver web page across network
time
 Java provides very convenient
multithreading to programmers
 We can add threads using inheritance
› We can supplement the existing capabilities
of the SimpleFileServer class
› We create a class ThreadedFileServer which
extends the existing SimpleFileServer
 You may have covered threads in the
Introductory Java Course
public class ThreadedFileServer extends SimpleFileServer
implements FileServer, Runnable
{
private static int index = 0;
public void dispatch(Socket s) {
super.s = s;
Thread thread =
new Thread(this, ”Server-" + (index++));
thread.start();
}
public void run() {
super.respond();
}
}
 Creates new threads within the virtual
machine
 Classes which start threads must
implement interface java.lang.Runnable
interface Runnable
{
/**
This is the method that will be run when the
new thread is started.
*/
public void run();
}
 Must create a Thread object associated
with each new thread using the
constructor
› Thread(Runnable run, String threadName)
 Start a thread with the method
› void start()
 Other useful methods can be used to set
priorities and interrupt a running thread
 Our threads do not share any common
memory locations (except for index)
 When threads read/write a shared
memory area access must be
synchronized
 Otherwise it is impossible to predict how
the system will behave
 Java has mechanisms for achieving this
 Starting a thread can be relatively
expensive when performance is critical
 Our threaded server creates a new Thread
for each file to be transferred
 A better approach is to create a pool of
threads and recycle them
› Create a pool of threads which are ready to
work when needed
› Have threads wait until work is available
 Better, but more complex so look at the
class sea.server.ThreadedFileServer2
 Our example web server performs a very
simple task
› Accept a request from a client
› Retrieve the appropriate document from disk
› Return the document to the client
 This is too limiting
› How do we implement searches?
 We need to be able to run programs within
the server to process user requests
› Accept a client request including arguments
› Run a program on the arguments
› Return results in the form of a document
 When we run small Java programs within a
browser these are referred to as Applets. . .
 so we run small Java programs within a
server these are “Servlets”
 A servlet is a program designed to process
a client request (which requires
interactivity).
› It processes arguments and formats its results as
a short lived document.
 HTML servlets are becoming a popular
mechanism for creating interactive servers.
 Traditionally programs were run on web
servers using Common Gateway
Interface (CGI) scripts written in
languages such as Perl.
› Must create a new interpreter process for
each client request
› Comparatively slow to start
› Expensive of memory resources when serving
several clients at the same time
› Interpreted programs are CPU intensive
 Servlets use Java objects which persist
between requests to the server
› Low latency since requests run in threads
› Offer performance advantages since programs
are compiled and can take advantage of JITs
and/or Hotspot JVMs.
› Servlet groups can share a JVM leading to
smaller memory footprints.
› Servlets run in a Sandbox offering protection
from malicious (or accidental) damage
› Programs are future proofed since WORA offers
better scope for server upgrades.
 Servlets are written in a similar fashion to
applets
› Write a new servlet class which extends
javax.servlet.http.HttpServlet (or just
implements javax.servlet.Servlet)
› Override certain methods to deal with requests
› Get your methods to create an HTML document
to return information to the client’s browser
› Load the servlet byte codes onto your web
server (for example apache/jserv)
 When the servlet is first loaded it makes a
single call to the method
› public void init(ServletConfig config)
 This may optionally be overridden to initialise
the state of the servlet (for example loading
state information from a file).
 When a servlet is finally unloaded it
makes a single call to the method
› public void destroy()
 If you wish to save to servlet state to a file (or
using JDBC) this is the method to override
 To handle an HTTP GET request implement
› protected void doGet(HttpServletRequest request,
HttpServletResponse response)
 If a browser visits your servlet this is where you get
to create a document for it to display
 To handle an HTTP POST request provide
› protected void doPost(HttpServletRequest request,
HttpServletResponse response)
 If your document contains an HTML form and the
user posts the results this is where you can extract
and process them
 Also methods for HTTP OPTIONS, TRACE and
DELETE (more exotic options)
 Two objects are passed as parameters to all
these handler methods:
 javax.servlet.http.HttpServletRequest
› Represents the formation that was passed to the
server when the user submitted the request by
visiting/posting to the servlets URL.
 javax.servlet.http.HttpServletResponse
› Used to construct a reponse document that is
returned to the user
 Each has a raft of methods so check the
Javadoc for details
 An web based chat room server
 A number of users can connect to the
servlet using browsers
 Read a list of the previous messages
 Optionally append new messages to the list
 Messages are attributed to a specific
author and are time stamped
 Messages do not persist after the chat
server is stopped (easy enough to rectify)
public class ChatServlet extends HttpServlet
{
Vector messages = new Vector();
public void init(ServletConfig config)
throws ServletException
{
super.init(config);
}
public void destroy()
{
// Currently does nothing
}
. . . .
}
protected void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
createDocument(response);
}
protected void createDocument(HttpServletResponse response)
throws IOException {
response.setContentType("text/html");
response.setHeader("pragma", "no-cache");
PrintWriter writer = response.getWriter();
writer.println("<HTML>");
writer.println("<HEAD><TITLE>Chat Servlet</TITLE></HEAD>");
writer.println("<BODY>");
Date now = new Date();
writer.println("Current server time is " + now + "<P>");
. . . .
writer.println("</BODY></HTML>");
writer.close();
}
for (int i = 0; i < messages.size(); i++) {
writer.println("<HR>");
String messageString = (String) messages.elementAt(i);
writer.println(messageString);
}
writer.println("<HR><FORM METHOD=POST>");
writer.println("Enter your name: “ +
“<INPUT TYPE=TEXT SIZE=25 NAME=name><BR>");
writer.println("Enter your message:<BR>” +
“<TEXTAREA ROWS=5 COLS=40 NAME=message>” +
“Type your message here</TEXTAREA><BR>");
writer.println(
"<INPUT TYPE=SUBMIT NAME=action VALUE=Submit>");
writer.println("<HR></FORM>");
protected synchronized void doPost(
HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException
{
String name = request.getParameter("name");
String message = request.getParameter("message");
if (name != null && message != null) {
Date timeStamp = new Date();
String messageString = "<B>Message " + messages.size() +
" from " + name + " at " + timeStamp +
":</B><BR>" + message + "<P>";
messages.add(messageString);
}
createDocument(response);
}
 Servlets offer better performance than most
of the previous CGI like technologies
 But CGI/Servlets concentrate the load on
the server
 When designing high throughput servers
only use servlets where you really need
interactivity
› Searches/Shopping carts
› Data that is very short lived (stock quotes)
 This also applies to low throughput servers
that might need to scale later
 Consider using periodic programs to
generate static documents on disk
› The cost of serving fixed documents will always
be less than the cost of server side execution
› Disk space is cheap!
 Consider using applets when possible
› This places the load on the client machines
rather than the server
 Finally consider using SMP and/or server
farms
› Complex and very expensive
 How can a chat reader find out when a
new message has been posted by another
author?
› Only by repeatedly hitting the Reload button!
 HTTP (& TCP/IP services in general) transfer
documents on the user’s request
 To push updates automatically from the
server you will need to:
› Start a reverse server within each client
› Use a multicast group
› Use a remote procedure call system such as RMI
or CORBA
 Java Server Pages is an extension to the
servlets API.
 With conventional servlets you embed the
HTML that you need inside a Java program.
 With JSP you embed your Java program
within a HTML document (by using special
tags).
 Works rather like JavaScript but the JSP
script runs on the server before the page is
dispatched to the user’s browser.
 For information about HTML try
http://www.w3schools.com
 You can download Sun’s servlet
development kit from their web site at
the http://java.sun.com/products/servlet
 You can download apache’s Tomcat
server from http://jakarta.apache.org
 For other information about Servlet
development try
http://www.servlets.com
 Read through the sample code to
convince yourself you understand what’s
going on
 Sample code can be downloaded from
http://ciips.ee.uwa.edu.au/~gareth
 Read the code documentation
 If you can, run the examples to check
they work
A java servers

Más contenido relacionado

La actualidad más candente

Effective out-of-container Integration Testing
Effective out-of-container Integration TestingEffective out-of-container Integration Testing
Effective out-of-container Integration TestingSam Brannen
 
Как мы взломали распределенные системы конфигурационного управления
Как мы взломали распределенные системы конфигурационного управленияКак мы взломали распределенные системы конфигурационного управления
Как мы взломали распределенные системы конфигурационного управленияPositive Hack Days
 
Play + scala + reactive mongo
Play + scala + reactive mongoPlay + scala + reactive mongo
Play + scala + reactive mongoMax Kremer
 
Learn Advanced JAVA at ASIT
Learn Advanced JAVA at ASITLearn Advanced JAVA at ASIT
Learn Advanced JAVA at ASITASIT
 
WebSockets wiith Scala and Play! Framework
WebSockets wiith Scala and Play! FrameworkWebSockets wiith Scala and Play! Framework
WebSockets wiith Scala and Play! FrameworkFabio Tiriticco
 
Learn to love networking on iOS
Learn to love networking on iOSLearn to love networking on iOS
Learn to love networking on iOSPaolo Tagliani
 
AWS Update | London - Elastic Beanstalk
AWS Update | London - Elastic BeanstalkAWS Update | London - Elastic Beanstalk
AWS Update | London - Elastic BeanstalkAmazon Web Services
 
Tomcat New Evolution
Tomcat New EvolutionTomcat New Evolution
Tomcat New EvolutionAllan Huang
 
Play Framework + Docker + CircleCI + AWS + EC2 Container Service
Play Framework + Docker + CircleCI + AWS + EC2 Container ServicePlay Framework + Docker + CircleCI + AWS + EC2 Container Service
Play Framework + Docker + CircleCI + AWS + EC2 Container ServiceJosh Padnick
 
Installing WordPress on AWS
Installing WordPress on AWSInstalling WordPress on AWS
Installing WordPress on AWSManish Jain
 
Apache web server tutorial for linux
Apache web server tutorial for linuxApache web server tutorial for linux
Apache web server tutorial for linuxSahad Sali
 
Securing docker containers
Securing docker containersSecuring docker containers
Securing docker containersMihir Shah
 
PowerUp - Automating Windows Privilege Escalation
PowerUp - Automating Windows Privilege EscalationPowerUp - Automating Windows Privilege Escalation
PowerUp - Automating Windows Privilege EscalationWill Schroeder
 
CON 2107- Think Async: Embrace and Get Addicted to the Asynchronicity of EE
CON 2107- Think Async: Embrace and Get Addicted to the Asynchronicity of EECON 2107- Think Async: Embrace and Get Addicted to the Asynchronicity of EE
CON 2107- Think Async: Embrace and Get Addicted to the Asynchronicity of EEMasoud Kalali
 
APACHE WEB SERVER FOR LINUX
APACHE WEB SERVER FOR LINUXAPACHE WEB SERVER FOR LINUX
APACHE WEB SERVER FOR LINUXwebhostingguy
 
Owin from spec to application
Owin from spec to applicationOwin from spec to application
Owin from spec to applicationdamian-h
 

La actualidad más candente (19)

Effective out-of-container Integration Testing
Effective out-of-container Integration TestingEffective out-of-container Integration Testing
Effective out-of-container Integration Testing
 
Как мы взломали распределенные системы конфигурационного управления
Как мы взломали распределенные системы конфигурационного управленияКак мы взломали распределенные системы конфигурационного управления
Как мы взломали распределенные системы конфигурационного управления
 
Play + scala + reactive mongo
Play + scala + reactive mongoPlay + scala + reactive mongo
Play + scala + reactive mongo
 
Learn Advanced JAVA at ASIT
Learn Advanced JAVA at ASITLearn Advanced JAVA at ASIT
Learn Advanced JAVA at ASIT
 
WebSockets wiith Scala and Play! Framework
WebSockets wiith Scala and Play! FrameworkWebSockets wiith Scala and Play! Framework
WebSockets wiith Scala and Play! Framework
 
Learn to love networking on iOS
Learn to love networking on iOSLearn to love networking on iOS
Learn to love networking on iOS
 
Distributed fun with etcd
Distributed fun with etcdDistributed fun with etcd
Distributed fun with etcd
 
AWS Update | London - Elastic Beanstalk
AWS Update | London - Elastic BeanstalkAWS Update | London - Elastic Beanstalk
AWS Update | London - Elastic Beanstalk
 
Tomcat New Evolution
Tomcat New EvolutionTomcat New Evolution
Tomcat New Evolution
 
Play Framework + Docker + CircleCI + AWS + EC2 Container Service
Play Framework + Docker + CircleCI + AWS + EC2 Container ServicePlay Framework + Docker + CircleCI + AWS + EC2 Container Service
Play Framework + Docker + CircleCI + AWS + EC2 Container Service
 
Installing WordPress on AWS
Installing WordPress on AWSInstalling WordPress on AWS
Installing WordPress on AWS
 
Apache web server tutorial for linux
Apache web server tutorial for linuxApache web server tutorial for linux
Apache web server tutorial for linux
 
Securing docker containers
Securing docker containersSecuring docker containers
Securing docker containers
 
PowerUp - Automating Windows Privilege Escalation
PowerUp - Automating Windows Privilege EscalationPowerUp - Automating Windows Privilege Escalation
PowerUp - Automating Windows Privilege Escalation
 
CON 2107- Think Async: Embrace and Get Addicted to the Asynchronicity of EE
CON 2107- Think Async: Embrace and Get Addicted to the Asynchronicity of EECON 2107- Think Async: Embrace and Get Addicted to the Asynchronicity of EE
CON 2107- Think Async: Embrace and Get Addicted to the Asynchronicity of EE
 
APACHE WEB SERVER FOR LINUX
APACHE WEB SERVER FOR LINUXAPACHE WEB SERVER FOR LINUX
APACHE WEB SERVER FOR LINUX
 
Owin from spec to application
Owin from spec to applicationOwin from spec to application
Owin from spec to application
 
Node js for enterprise
Node js for enterpriseNode js for enterprise
Node js for enterprise
 
So Many Docker Platforms...so little time
So Many Docker Platforms...so little timeSo Many Docker Platforms...so little time
So Many Docker Platforms...so little time
 

Destacado

Subic brent
Subic brent Subic brent
Subic brent jenniech
 
H τρίτη κλίση των ουσιαστικών
H τρίτη κλίση των ουσιαστικώνH τρίτη κλίση των ουσιαστικών
H τρίτη κλίση των ουσιαστικώνEvangelia Patera
 
The search for_extraterrestrial_civilizations_with_large_energy_supplies
The search for_extraterrestrial_civilizations_with_large_energy_suppliesThe search for_extraterrestrial_civilizations_with_large_energy_supplies
The search for_extraterrestrial_civilizations_with_large_energy_suppliesSérgio Sacani
 
40分でわかるHadoop徹底入門 (Cloudera World Tokyo 2014 講演資料)
40分でわかるHadoop徹底入門 (Cloudera World Tokyo 2014 講演資料) 40分でわかるHadoop徹底入門 (Cloudera World Tokyo 2014 講演資料)
40分でわかるHadoop徹底入門 (Cloudera World Tokyo 2014 講演資料) hamaken
 

Destacado (9)

A java servers
A java serversA java servers
A java servers
 
Subic brent
Subic brent Subic brent
Subic brent
 
Nepse Technical Analysis October 11 - October 15, 2015
Nepse Technical Analysis October 11 - October 15, 2015Nepse Technical Analysis October 11 - October 15, 2015
Nepse Technical Analysis October 11 - October 15, 2015
 
Content Queen Portfolio
Content Queen PortfolioContent Queen Portfolio
Content Queen Portfolio
 
chocolate ppt orignal
chocolate ppt orignalchocolate ppt orignal
chocolate ppt orignal
 
H τρίτη κλίση των ουσιαστικών
H τρίτη κλίση των ουσιαστικώνH τρίτη κλίση των ουσιαστικών
H τρίτη κλίση των ουσιαστικών
 
The search for_extraterrestrial_civilizations_with_large_energy_supplies
The search for_extraterrestrial_civilizations_with_large_energy_suppliesThe search for_extraterrestrial_civilizations_with_large_energy_supplies
The search for_extraterrestrial_civilizations_with_large_energy_supplies
 
40分でわかるHadoop徹底入門 (Cloudera World Tokyo 2014 講演資料)
40分でわかるHadoop徹底入門 (Cloudera World Tokyo 2014 講演資料) 40分でわかるHadoop徹底入門 (Cloudera World Tokyo 2014 講演資料)
40分でわかるHadoop徹底入門 (Cloudera World Tokyo 2014 講演資料)
 
Android ppt
Android ppt Android ppt
Android ppt
 

Similar a A java servers

Similar a A java servers (20)

Node.js Workshop - Sela SDP 2015
Node.js Workshop  - Sela SDP 2015Node.js Workshop  - Sela SDP 2015
Node.js Workshop - Sela SDP 2015
 
node.js: Javascript's in your backend
node.js: Javascript's in your backendnode.js: Javascript's in your backend
node.js: Javascript's in your backend
 
Node.js: The What, The How and The When
Node.js: The What, The How and The WhenNode.js: The What, The How and The When
Node.js: The What, The How and The When
 
Introduction to node.js
Introduction to node.jsIntroduction to node.js
Introduction to node.js
 
Ftp servlet
Ftp servletFtp servlet
Ftp servlet
 
Servlets
ServletsServlets
Servlets
 
Ajp notes-chapter-06
Ajp notes-chapter-06Ajp notes-chapter-06
Ajp notes-chapter-06
 
Introduction to Node JS1.pdf
Introduction to Node JS1.pdfIntroduction to Node JS1.pdf
Introduction to Node JS1.pdf
 
Servlets
ServletsServlets
Servlets
 
Play Framework: async I/O with Java and Scala
Play Framework: async I/O with Java and ScalaPlay Framework: async I/O with Java and Scala
Play Framework: async I/O with Java and Scala
 
1 java servlets and jsp
1   java servlets and jsp1   java servlets and jsp
1 java servlets and jsp
 
Advance Java Topics (J2EE)
Advance Java Topics (J2EE)Advance Java Topics (J2EE)
Advance Java Topics (J2EE)
 
AJppt.pptx
AJppt.pptxAJppt.pptx
AJppt.pptx
 
Introduction to node.js GDD
Introduction to node.js GDDIntroduction to node.js GDD
Introduction to node.js GDD
 
Java servlet technology
Java servlet technologyJava servlet technology
Java servlet technology
 
J2ee servlet
J2ee servletJ2ee servlet
J2ee servlet
 
Java servlets
Java servletsJava servlets
Java servlets
 
Express node js
Express node jsExpress node js
Express node js
 
Servlet by Rj
Servlet by RjServlet by Rj
Servlet by Rj
 
Servlets
ServletsServlets
Servlets
 

Último

08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 

Último (20)

08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 

A java servers

  • 1.
  • 2.
  • 3.  To create a simple HTTP server in Java  To use the implementation to illustrate a number of advanced Java features: › TCP/IP Sockets and Server Sockets › Interfaces › Software components (more from John later) › Multithreading  To show how to create executable server objects (using Sun’s Servlets API)
  • 4.  Java Network Programming, Elliotte Rusty Harold, O’Reilly and Associates, 1997, ISBN 1-56592-227-1  TCP/IP Network Administration, Second Edition, Craig Hunt, O’Reilly and Associates, 1997, ISBN 1-56592-322-7  The Java Developer’s connection: http://www.javasoft.com/jdc  The Javadoc documentation
  • 5.  Server must be able to process HTTP/1.0 file transfer requests and deliver files  Connections are to be made via TCP/IP  Must be efficient and prompt  Must be simple to understand and elegant in design
  • 6.  Developed by Tim Berners-Lee at CERN  Like most Internet protocols it is described in an RFC (Request for Comment document): RFC1945  May be downloaded from the Internet Engineering Task Force’s web site: http://www.ietf.org
  • 7.  Some of you may have covered this in the introductory Java course  Servers have a listener loop › Loop until the server is shutdown  Wait for a client to request a connection  Read the details of the client’s request  Provide the requested information to the client  Here’s the listener loop from our example:
  • 8. ServerSocket socket = new ServerSocket(80, 5); public void listen() throws IllegalAccessException, InstantiationException, IOException { for (;;) { System.err.println("HttpServer: waiting..."); Socket s = socket.accept(); FileServer f = createFileServer(); f.dispatch(s); } }
  • 9. 2037 80 2037 1583 2037 1583 Client (sid) Server (fred) ServerSocket ss. s = ss.accept() s = new Socket (“fred”, 80) Socket s s.getInputStream() s.getOuputStream() s.getInputStream() s.getOuputStream()
  • 10.  Good software is designed in a modular fashion avoiding stovepipe designs!  This is a form of software components  Java has strong support for components  Components hide their implementation behind interfaces  An interface defines a contract between the supplier/server and the user/client.
  • 11. ServerSocket socket = new ServerSocket(80, 5); public void listen() throws IllegalAccessException, InstantiationException, IOException { for (;;) { System.err.println("HttpServer: waiting..."); Socket s = socket.accept(); FileServer f = createFileServer(); f.dispatch(s); } }
  • 12.  Simplifies client implementation  Clients do not need to worry about the implementation details  Interfaces encapsulate state of different subsystems ⇒ side effects reduced  Define clear boundaries between different teams of programmers  Clients can substitute alternative implementations: polymorphism  Clients can purchase off the shelf solutions: software components
  • 13. Software Component Client Program Interface /ublic class HttpServer { /** Listens indefinitely for transfer requests and creates a server instance for each request. */ public void listen() throws IllegalAccessException, InstantiationException, IOException { for (;;) { /* Block, waiting for a request to occur then spawns a new (anonymous) socket with which to deal with the request. */ System.err.println("HttpServer: waiting..."); Socket s = socket.accept(); /* Create a file server to deal with the new socket. */ FileServer f = createFileServer(); f.dispatch(s); } } public static void main(String[] args) { try { HttpServer htts = new HttpServer("sea.server.ThreadedFileServer"); htts.listen(); } catch (Exception e) { System.err.println("HttpServer: failed due to exception:n" + e); } }
  • 14. public interface FileServer { /** This method allows an incoming HTTP request to initiate a file dispatch. The socket will provide an input stream (which is at the beginning) from which an HTTP/1.0 header request may be read.<p> It also provides an output stream on which the request should be delivered. The delivery should have an HTTP/1.0 header prepended. @param s The socket on which a request is being made. Once this method has returned the socket will have been closed by the dispatcher. */ public void dispatch(Socket s); }
  • 15.  Each interface is a contract between two parties  The contract should be made as strict and precise as possible  Avoid unnecessary ambiguity  Document the contract within the interface’s source file using Javadoc
  • 16.  Two flavours of FileServer have been provided using deferred instantiation › A simple one but with low performance: sea.server.SimpleFileServer › A server that uses multiple threads to increase performance: sea.server.ThreadedFileServer › A server which uses a pool of threads to achieve the maximum possible performance: sea.server.ThreadedServer2
  • 17.  Must implement the FileServer interface so that it can plug in to the HttpServer  Reads the HTTP request from the Socket’s input stream  Decides which file is required  Reads the file and spools to the Socket’s output stream.
  • 18. public class SimpleFileServer implements FileServer { protected Socket s = null; public void dispatch(Socket s) { this.s = s; respond(); } . . . . }
  • 19.  Must get an input stream so that we can analyse the request  Socket provides the method › InputStream getInputStream(); Socket s; InputStream inStream = s.getInputStream(); InputStreamReader reader = new InputStreamReader(inStream); BufferedReader input = new BufferedReader(reader);
  • 20.  Request consists of a number of lines of text separated by “rn”  First line is all this server is interested in  A typical request might be of the form: GET /path/to/file.html HTTP/1.0 Accept: text/html Accept: image/gif User-Agent: Lynx/2.4
  • 21.  Cuts out the file name  Looks for the file relative to the current working directory (not portable!!)  If the file is a directory look for the file “index.html” in the directory  If the file does not exist then respond with an error (code 404)
  • 22.  Must construct a header for the response  Code 200 means success  Simple header takes the following form: HTTP/1.0 200 OK Server: SEA/1.0 MIME-version: 1.0 Content-type: text/html Data starts after blank line. . . More data, etc. . .
  • 23.  Get the output stream from the Socket › OutputStream getOutputStream()  Spool (copy) the file contents into the socket  If the MIME type is textual then we must make sure the lines are delimited by “rn”.  Otherwise we pass the file unmodified
  • 24.  The SimpleFileServer is completely sequential. › It handles one request at a time.  Reading a file from disk takes a long time (around 10ms)  The server will be sitting idle while it waits for the file to load (wasting up to 106 instruction cycles)  Other web browsers will be kept waiting
  • 25. Start HTTP request loading Block awaiting disk availability Deliver web page across network time
  • 26.  Threaded servers can process several requests at once. Each request is handled by a separate thread.  This doesn’t increase the overall amount of work done (unless using SMP)  . . . but it does reduce the wastage!  Threaded operation is worthwhile when threads are expected to block, awaiting I/O operations
  • 27. Start HTTP request loading Block awaiting disk availability Deliver web page across network time
  • 28.  Java provides very convenient multithreading to programmers  We can add threads using inheritance › We can supplement the existing capabilities of the SimpleFileServer class › We create a class ThreadedFileServer which extends the existing SimpleFileServer  You may have covered threads in the Introductory Java Course
  • 29. public class ThreadedFileServer extends SimpleFileServer implements FileServer, Runnable { private static int index = 0; public void dispatch(Socket s) { super.s = s; Thread thread = new Thread(this, ”Server-" + (index++)); thread.start(); } public void run() { super.respond(); } }
  • 30.  Creates new threads within the virtual machine  Classes which start threads must implement interface java.lang.Runnable interface Runnable { /** This is the method that will be run when the new thread is started. */ public void run(); }
  • 31.  Must create a Thread object associated with each new thread using the constructor › Thread(Runnable run, String threadName)  Start a thread with the method › void start()  Other useful methods can be used to set priorities and interrupt a running thread
  • 32.  Our threads do not share any common memory locations (except for index)  When threads read/write a shared memory area access must be synchronized  Otherwise it is impossible to predict how the system will behave  Java has mechanisms for achieving this
  • 33.  Starting a thread can be relatively expensive when performance is critical  Our threaded server creates a new Thread for each file to be transferred  A better approach is to create a pool of threads and recycle them › Create a pool of threads which are ready to work when needed › Have threads wait until work is available  Better, but more complex so look at the class sea.server.ThreadedFileServer2
  • 34.  Our example web server performs a very simple task › Accept a request from a client › Retrieve the appropriate document from disk › Return the document to the client  This is too limiting › How do we implement searches?  We need to be able to run programs within the server to process user requests › Accept a client request including arguments › Run a program on the arguments › Return results in the form of a document
  • 35.  When we run small Java programs within a browser these are referred to as Applets. . .  so we run small Java programs within a server these are “Servlets”  A servlet is a program designed to process a client request (which requires interactivity). › It processes arguments and formats its results as a short lived document.  HTML servlets are becoming a popular mechanism for creating interactive servers.
  • 36.  Traditionally programs were run on web servers using Common Gateway Interface (CGI) scripts written in languages such as Perl. › Must create a new interpreter process for each client request › Comparatively slow to start › Expensive of memory resources when serving several clients at the same time › Interpreted programs are CPU intensive
  • 37.  Servlets use Java objects which persist between requests to the server › Low latency since requests run in threads › Offer performance advantages since programs are compiled and can take advantage of JITs and/or Hotspot JVMs. › Servlet groups can share a JVM leading to smaller memory footprints. › Servlets run in a Sandbox offering protection from malicious (or accidental) damage › Programs are future proofed since WORA offers better scope for server upgrades.
  • 38.  Servlets are written in a similar fashion to applets › Write a new servlet class which extends javax.servlet.http.HttpServlet (or just implements javax.servlet.Servlet) › Override certain methods to deal with requests › Get your methods to create an HTML document to return information to the client’s browser › Load the servlet byte codes onto your web server (for example apache/jserv)
  • 39.  When the servlet is first loaded it makes a single call to the method › public void init(ServletConfig config)  This may optionally be overridden to initialise the state of the servlet (for example loading state information from a file).  When a servlet is finally unloaded it makes a single call to the method › public void destroy()  If you wish to save to servlet state to a file (or using JDBC) this is the method to override
  • 40.  To handle an HTTP GET request implement › protected void doGet(HttpServletRequest request, HttpServletResponse response)  If a browser visits your servlet this is where you get to create a document for it to display  To handle an HTTP POST request provide › protected void doPost(HttpServletRequest request, HttpServletResponse response)  If your document contains an HTML form and the user posts the results this is where you can extract and process them  Also methods for HTTP OPTIONS, TRACE and DELETE (more exotic options)
  • 41.  Two objects are passed as parameters to all these handler methods:  javax.servlet.http.HttpServletRequest › Represents the formation that was passed to the server when the user submitted the request by visiting/posting to the servlets URL.  javax.servlet.http.HttpServletResponse › Used to construct a reponse document that is returned to the user  Each has a raft of methods so check the Javadoc for details
  • 42.  An web based chat room server  A number of users can connect to the servlet using browsers  Read a list of the previous messages  Optionally append new messages to the list  Messages are attributed to a specific author and are time stamped  Messages do not persist after the chat server is stopped (easy enough to rectify)
  • 43. public class ChatServlet extends HttpServlet { Vector messages = new Vector(); public void init(ServletConfig config) throws ServletException { super.init(config); } public void destroy() { // Currently does nothing } . . . . }
  • 44. protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { createDocument(response); } protected void createDocument(HttpServletResponse response) throws IOException { response.setContentType("text/html"); response.setHeader("pragma", "no-cache"); PrintWriter writer = response.getWriter(); writer.println("<HTML>"); writer.println("<HEAD><TITLE>Chat Servlet</TITLE></HEAD>"); writer.println("<BODY>"); Date now = new Date(); writer.println("Current server time is " + now + "<P>"); . . . . writer.println("</BODY></HTML>"); writer.close(); }
  • 45. for (int i = 0; i < messages.size(); i++) { writer.println("<HR>"); String messageString = (String) messages.elementAt(i); writer.println(messageString); } writer.println("<HR><FORM METHOD=POST>"); writer.println("Enter your name: “ + “<INPUT TYPE=TEXT SIZE=25 NAME=name><BR>"); writer.println("Enter your message:<BR>” + “<TEXTAREA ROWS=5 COLS=40 NAME=message>” + “Type your message here</TEXTAREA><BR>"); writer.println( "<INPUT TYPE=SUBMIT NAME=action VALUE=Submit>"); writer.println("<HR></FORM>");
  • 46. protected synchronized void doPost( HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String name = request.getParameter("name"); String message = request.getParameter("message"); if (name != null && message != null) { Date timeStamp = new Date(); String messageString = "<B>Message " + messages.size() + " from " + name + " at " + timeStamp + ":</B><BR>" + message + "<P>"; messages.add(messageString); } createDocument(response); }
  • 47.  Servlets offer better performance than most of the previous CGI like technologies  But CGI/Servlets concentrate the load on the server  When designing high throughput servers only use servlets where you really need interactivity › Searches/Shopping carts › Data that is very short lived (stock quotes)  This also applies to low throughput servers that might need to scale later
  • 48.  Consider using periodic programs to generate static documents on disk › The cost of serving fixed documents will always be less than the cost of server side execution › Disk space is cheap!  Consider using applets when possible › This places the load on the client machines rather than the server  Finally consider using SMP and/or server farms › Complex and very expensive
  • 49.  How can a chat reader find out when a new message has been posted by another author? › Only by repeatedly hitting the Reload button!  HTTP (& TCP/IP services in general) transfer documents on the user’s request  To push updates automatically from the server you will need to: › Start a reverse server within each client › Use a multicast group › Use a remote procedure call system such as RMI or CORBA
  • 50.  Java Server Pages is an extension to the servlets API.  With conventional servlets you embed the HTML that you need inside a Java program.  With JSP you embed your Java program within a HTML document (by using special tags).  Works rather like JavaScript but the JSP script runs on the server before the page is dispatched to the user’s browser.
  • 51.  For information about HTML try http://www.w3schools.com  You can download Sun’s servlet development kit from their web site at the http://java.sun.com/products/servlet  You can download apache’s Tomcat server from http://jakarta.apache.org  For other information about Servlet development try http://www.servlets.com
  • 52.  Read through the sample code to convince yourself you understand what’s going on  Sample code can be downloaded from http://ciips.ee.uwa.edu.au/~gareth  Read the code documentation  If you can, run the examples to check they work