Fundamentals of Web Programming

indexadjustmentInternet and Web Development

Nov 13, 2013 (4 years ago)

80 views

20
-
753: Fundamentals of

Web Programming

1

Lecture 17: Advanced Java

Fundamentals of

Web Programming

Lecture 17:

Advanced Java

20
-
753: Fundamentals of

Web Programming

2

Lecture 17: Advanced Java

Today’s Topics


Java Servlets

20
-
753: Fundamentals of

Web Programming

3

Lecture 17: Advanced Java

Java Servlets


Analogy:


An
applet

is a small piece of code that
runs inside the
client

(web browser),
extending its functionality


A
servlet

is a small piece of code that
runs inside the
server

(web server),
extending its functionality

20
-
753: Fundamentals of

Web Programming

4

Lecture 17: Advanced Java

Applet Security Model

Web Server

Browser

Connecting to the web server

that served the applet is OK

Data Server

Connecting to a different

server is
not

OK

Java
Applet

Programs written in Java can include code that connects


to any host on the Internet… what about applets?

20
-
753: Fundamentals of

Web Programming

5

Lecture 17: Advanced Java

Java Servlets

Web Server

Browser

Data Server

What if we want to provide a web site that allows our

customers to access information on a different server?

Servlets can access

any server

on the

network

The server can include servlet

code, which runs as an application

(outside the applet security model)

Java
Servlet

middleware

20
-
753: Fundamentals of

Web Programming

6

Lecture 17: Advanced Java

Servlet Advantages


Allows more flexible networking
(excellent for middleware)


Looks just like a script to the client
(no extra client
-
side processing)


Loaded into the web server once
(unlike Perl scripts, which load into
memory every time they are
called)

20
-
753: Fundamentals of

Web Programming

7

Lecture 17: Advanced Java

Servlet Requirements


You need a servlet
-
capable web
server


Apache 1.3


Sun’s Java Web Server


Programmed using the Servlet API

(special Java class library)


Servlet API is very similar to CGI
libraries for Perl


20
-
753: Fundamentals of

Web Programming

8

Lecture 17: Advanced Java

Animation with Applets


Sun’s Animator class is a useful
tool for animating web pages


Example Images:

http://www.lti.cs.cmu.edu/ehnweb/applets/Animator/Foo/sheet.html


Example Applet:

http://www.lti.cs.cmu.edu/ehnweb/applets/Animator/Foo