What are Java Servlets?
An extremely popular Java substitute for CGI
scripts.
They are programs to be run on a web server.
The web page is based on the data submitted by
the user.
More efficient, easier to use, Powerful and
Portable.
1
Java Servlets
They are Java application programs that are
resident on the server and are alternatives to CGI
programs.
Java Servlets allow you to build
Web page based on the users input data
Web page that changes frequently
More efficient, easier to use, more powerful and
portable.
2
Servlets Advantages
Platform and vendor independence
Supported by all the major web servers
Integration
Take advantages of all the Java technologies, JDBC,
Enterprise JavaBeans (EJB).
Efficiency
A single process that runs until the servlet-based
application is shut down.
Scalability extremely scalable.
Robustness and security
A strongly typed programming language.
Servlet Example
What is JSP?
It is JavaServer Pages that built on top of Java servlets in
late 1999.
In the early days of the Web, the only tool for developing
dynamic web content was CGI. For every request, the web
server creates a process (not efficient).
The Java Servlet API has introduced in 1997, however,
HTML code has to be embedded inside programs. (lot of
out.println())
JSP provides a development model for the web authors to
experience all the server-side technologies.
5
JSP page translation and processing
phases
Translation phase
Hello.jsp
Read
Request
helloServlet.java
Generate
Client
Response
Server
Execute
helloServlet.class
6
Processing phase
A simple example
Java Servlet & JSP
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class HelloWorld extends HttpServlet {
<HTML>
<HEAD>
<TITLE>Hello</TITLE>
</HEAD>
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
res.setContentType("text/html");
PrintWriter out = res.getWriter();
<BODY>
<H1>
<%
out.println("<HEAD><TITLE>Hello World</TITLE></HEAD>");
if (request.getParameter("name") == null)
out.println("<BODY>");
{
out.println("<BIG>Hello World</BIG>");
out.println("Hello World");
} else {
out.println("</BODY></HTML>");
out.println("Hello, " + request.getParameter("name"));
}
}
}
%>
7
</H1>
</BODY>
</HTML>
out.println("<HTML>");
Template Pages
Server Page Template
Resulting HTML
<html>
<html>
<title>
<title>
A simple example
A simple example
</title>
translation
</title>
<body color=#FFFFFF>
<body color=#FFFFFF>
The time now is
The time now is
<%= new java.util.Date() %>
Tue Nov 5 16:15:11 PST 2002
</body>
</body>
</html>
</html>
What you need to get started?
A Personal Computer with an Internet
connection, that allows you to download the
software you need.
A Java 2-compatible Java Software Development
Kit (Java 2 SDK)
A JSP 1.1-enabled web server, such as Apache
Tomcat
9
JSP vs. ASP
ASP Technology
JSP Technology
Web Server
IIS or Personal Web Server
Any Web Server
Platforms
Microsoft Windows
Most popular platforms
Reusable
components
No
JavaBeans, JSP tags
Security against
System crashes
No
Yes
Scripting
Language
VBScript, Jscript
Java
JSP is platform and server independent.
ASP relies on Microsoft Platforms and Servers.
10
ASP & JSP
<html>
<head><title>Hello World by ASP</title></head>
<body>
<font size=12>
<%
response.write Hello INE2720 Students and the World!"
%>
</font>
</body>
<html>
<head><title>Hello World by JSP</title></head>
<body>
<font size=12>
<%
out.println("Hello INE2720 Students and the World!");
%>
</font>
</body>
11
Web Services
What are Web services?
They are a distributed computing architecture.
Who is using Web services now?
Industry technologies
Which approach should we use - .NET or J2EE?
Requestor, Registry, Provider
12
Critical Elements of a Basic
Web Services Architecture
Format
XML (Format)
Services
UDDI (Publish)
WSDL (Find)
A directory service
A protocol for
applications to find
a service
Network
For presenting data and information
SOAP (Bind)
A protocol that
enables
applications to
agree the
communication
The Internet
The Internet, using TCP/IP protocols
13
Service-Oriented Architecture
Find - UDDI
Requestor
Registry
Bind
WSDL, SOAP
Publish - UDDI
14
Provider
References
Internet and World Wide Web How to Program
Deitel, Deitel and Nieto
The End.
Thank you for your patience!
15