Server-side Technologies
Download
Report
Transcript Server-side Technologies
Server-side Technologies
• Technologies that exist
at the server side
• Where the real work
occurs
1
Server-side Technologies
• Looking at ….
– Client-side scripting v Server-side scripting
– Factors in selecting a technology
– Older and New technologies
• CGI, Fast CGI, Mod Perl, Active Server Pages
(ASP), Cold Fusion
– Overview of Servlets
– Introduction to Java Server Pages (JSP)
2
Client-side scripting v Serverside scripting
• Client-side scripting
– Validates user input
– Accesses the browser
– Enhances Web pages with ActiveX® controls, applets,
etc.
– Manipulates browser documents
• Client-side validation
– Reduces number of requests that need to be passed to server
• Client-side scripting limitations
– Browser dependency
– Viewable to users through View Source command
• JavaScript most popular client-side script
3
Client-side scripting v Serverside scripting
• Server-side scripts
– Provides programmers greater flexibility
– Generates custom responses for clients
– Contains greater programmatic capabilities than
client-side equivalents
– Has access to server-side software that extend
server functionality
4
Server-side options
•
•
•
•
•
•
•
•
Common Gateway Interface (CGI)
Fast CGI
Mod Perl
Active Server Pages (ASP)
Personal Home Pages (PHP)
Cold Fusion
Java Servlets
Java Server Page (JSP)
5
Common Features
• All server-side frameworks share a common
set of features
– Read data submitted by the user
– Generate HTML dynamically based on user
input
– Determine information about the client browser
– Access database systems
– Exploit the HTTP protocol
6
Decision Points
• When evaluating which server-side technology to
use, you need to consider a number of critical
factors
– Ease of development
• How easily can you build new applications
– Performance
• How fast can the technology respond to queries
– Scalability
• Can the technology scale to thousands, even millions of
users?
– Security
• Are there any inherent security vulnerabilities?
7
Common Gateway Interface
(CGI)
• CGI represents one of the earliest, practical
methods for generating web content
• Primarily written in the Perl programming
language
• Unfortunately, some CGI programs suffer
from scalability and performance problems
– Let us see why this happens
8
CGI Architecture
• Browser initiates request
• Web server receives request
• For each new request, web server spawns a new
operating system process to execute the CGI/Perl
program
Create new
process
Browser
Web
Server
Perl/CGI
9
CGI Architecture
• For each browser request, the web server must
spawn a new operating system process
CGI/Perl 1
Browser 1
Browser 2
Web
Server
CGI/Perl 2
Browser N
Create new
process
CGI/Perl N
10
CGI Architecture
• Spawning a new operating system process
for each request takes time and memory
• Hence, CGI programs have inherent
scalability and performance problems
• Almost all other server architectures address
these problems
11
Fast CGI
• Developed by Open Market as an option for
developing faster, more scalable CGI programs
• Works by creating a pool of processes for
handling CGI requests
• When a server receives a CGI request, Fast
CGI picks up one of the processes from the
pool and assigns it to the task
• Without the overhead of creating new
processes each time, Fast CGI is much quicker
than traditional CGI
12
Mod Perl
• A module of the Apache Web server
• Embeds the Perl interpreter directly within the
web server
• Perl programs are therefore precompiled
• Since Perl is embedded within the server, Mod
Perl does not need to create a new process for
each request
• Like Fast CGI, Mod Perl is much faster than
traditional CGI
13
Server Extensions
• Several web servers provide extension APIs
(Application Programming Interfaces)
– Netscape provides (NSAPI)
– Microsoft provides (ISAPA)
• Similar to Mod Perl, these programs run directly
within the web server
• Hence, Server Extensions are much faster than
traditional CGI
• Usually written in C/C++, they are not portable
across web servers
– E.g. if you develop using Netscape NSAPI, you cannot14
run it on Microsoft ISAPA
ASP (Active Server Pages)
• Developed by Microsoft
• Runs on Microsoft’s web server: IIS (Internet
Information Server)
• Developers add ASP code directly to their
HTML pages
• When a client requests a page, the web server
takes the HTML page, runs the ASP code
within the page, and returns the result in
another HTML page
• Faster than traditional CGI but only works
15
with Microsoft’s IIS
Cold Fusion
• Developed by Allaire Corporation
• Provides excellent database access and tools
• Very good technology for Rapid
Prototyping and Rapid development
16
PHP (Personal Home Pages)
• An open source project developed by
volunteers
• Provides simple and powerful database
access and tools
• Good for Rapid Application Development
17
Servlet
• Java’s answer to the CGI script
• Do not confuse a servlet with an applet
– Applet: a java program that runs within a
browser
– Servlet: a java program that runs within a web
server
• Rapidly becoming most popular technology
for developing web based applications
18
Servlet Overview
• Servlets are a significant development in
client/server computing for the web
• Java Servlet API – standard extension to
Java
• Provides a Java class that can be loaded
dynamically to expand the functionality of a
Java-enabled server
• Does not require Java support on the client
side
19
Servlet Overview
• Provides a generic mechanism for extending
the functionality of any kind of server (not just
web servers)
– e.g. could be used to extend the functionality of
a Java-based ftp server, or a mail server to scan
for viruses attached to email
• Makes it easier for applets to communicate
with the server
• Created to solve one basic need recognised:
Generating dynamic web content
20
History of Servlets
• In late 1996, the use of Java on the server
side was developing
• Allows getting away from the use of sockets
on the server side
– Software vendors were each developing their
own approach
– Problem: each technology was tied to a
particular vendor server program
21
History of Servlets
• Better to have a generic technology so that
server programs could have the “write-once,
run-anywhere” approach
• Early 1997, JavaSoft (Sun Microsystems)
released the Servlet API
• Designed to work on Java and non-Java
based servers
• Most web servers support Servlets
22
General mechanism
• Execute within the server’s process space
• Each servlet handled by a separate thread
within the server process, not as separate
processes (as in CGI).
• Servlets are portable across different web
servers and different operating systems
• Fast, powerful and portable replacements to
CGI scripts
23
General mechanism
• Persist between invocations (CGI scripts
reloaded), resulting in significant
performance benefits over CGI programs
• Servlets have full access to the Java APIs
and also to third party component classes
(e.g. database connections, etc.)
24
Places where Servlets can be
used
• Accessed by name to generate a HTML
page
• Embedded inside a HTML page as a server
side include
– These are useful when a web page is mostly
static info but contains small sections of
dynamically-generated info
• Embedded inside a HTML page using Java
Server Pages (JSP) – see these later
25
3 types of servlet engine
• Standalone
– Server that contains built in support for Servlets
(e.g. Tomcat)
• Does not exist for many web servers
– Disadvantage: have to wait for a new server release
to get latest servlet support
• Add-on
– A plug-in for an existing web server
– Many have been written for servers (e.g. Apache)
• Embedded
– Lightweight servlet platform that can be embedded26
in another application
Advantages of Servlets
• Servlets have 6 main advantages
–
–
–
–
–
–
Efficient
Convenient
Powerful
Portable
Secure
Inexpensive
• Let us see why
27
Advantages of Servlets
• Efficient
– For each browser request, the servlet spawns a
light weight thread
– This is faster and more efficient than spawning
a new operating system process
– Hence, servlets have better performance and
scalability than traditional CGI
28
Advantages of Servlets
• Convenient
– Servlets include built-in functionality for:
•
•
•
•
Reading HTML from data
Handling cookies
Tracking user sessions
Setting HTTP headers
– Java is an object-oriented language which
arguably can make development easier
29
Advantages of Servlets
• Powerful
– Servlets can talk directly to web servers
– Multiple servlets can share data
• Particularly important for maintaining database
connections
– Includes powerful techniques for tracking user
sessions
30
Advantages of Servlets
• Portable
– One of the advantages of Java is its portability
across different operating systems
– Servlets have the same advantages (they are
written in Java)
• Can be written on a Windows platform and run on a
UNIX operating system
– Servlets can be run on any Java-enabled web
server with no code changes
31
Advantages of Servlets
• Secure
– Traditional CGI programs have a number of
known security vulnerabilities
– Hence, a separate CGI/Perl script is usually
required to provide the extra security required
– Java itself has a number of built-in security
features
– Therefore, Servlets are regarded to be more
secure than CGI programs
32
Advantages of Servlets
• Inexpensive
– You can download free servlet kits for
development
– As many servlets that are required can be
developed for free and run on many free Javaenabled web servers
33
Servlets Example
import javax.servlet.*;
import javax.servlet.http.*;
public class HelloWorld extends HttpServlet
{
public void doGet(HttpServletRequest request, HttpServletResponse response) throws
IOException, ServletException
{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<body>");
out.println("<head>");
out.println("<title>Hello World!</title>");
out.println("</head>");
out.println("<body>");
out.println("<h1>Hello World!</h1>");
out.println("</body>");
out.println("</html>");
}
}
34
Server Pages
• Microsoft IIS + ASP (Active Server Pages)
• Sun followed suit + JSP (JavaServer Pages)
35
Java Server Pages
• Related to Java servlets
– An extension of the Java servlet API
• Can be used alone or in conjunction with
servlets
• Another method for developing server side
applications
• We will look at these in more detail in next
lecture
36
References
• Check out
– Fast CGI
• http://www.fastcgi.com
– Mod Perl
• http://perl.apache.org
– Active Server Pages (ASP)
• http://www.microsoft.com
– Cold Fusion
• http://www.allaire.com
– PHP
• http://www.php.net
– Servlet and Java Server Page (JSP)
• http://java.sun.com
37
Summary
• We have looked at:
– Client-side scripting v Server-side scripting
– Factors in selecting a technology
– Older and New technologies
• CGI, Fast CGI, Mod Perl, Active Server Pages
(ASP), Cold Fusion
– Overview of Servlets
– Introduction to Java Server Pages (JSP)
38