13 May 2002 |
Reading for Session 9, which covers Day 26: Writing Java Servlets and
Day 27: Using JavaServer Pages (JSP), even though students do not have these chapters in the paperback edition |
Whereas a CGI (common gateway interface) script loads a new copy in memory for each user of the script, a Java servlet only loads one copy, and spawns a thread for each user. A web page with a form (such as for online credit card purchases) can call a web server using an HTTP request (GET or POST) with a URL. A Java servlet can take advantage of cookies to write and retrieve data on the client machine.
----------
http://java.sun.com/docs/books/tutorial/servlets/index.html
The Servlets trail teaches you about servlets, the bodies of code that run inside servers, and extend their functionality. For example, servlets offer an efficient platform-independent replacement for CGI scripts. Servers that can host servlets are Java-enabled servers that respond to client requests.
Overview of Servlets tells you what servlets are, and how you can use
them. The lesson also introduces the example servlets used in this trail.
Client Interaction shows you how to write servlets that interact with
clients. The servlets in this lesson respond to HTTP GET, HEAD and POST
requests. The lesson also discusses threading issues, and shows you how to avoid
problems by creating a servlet that responds to one client at a time.
The Life Cycle of a Servlet discusses the significant events in the
life of a servlet and shows you how to customize servlet initialization and
shutdown.
Saving Client State shows you how to use session tracking and
cookies.
Servlet Communication shows you how to have your servlet communicate
with other servlets and other resources, such as CGI scripts.
Running Servlets describes how to test your servlets with Tomcat and
the Java Servlet Development Kit (JSDK) version 2.1.
Calling Servlets shows you how to call servlets from a browser and
within an HTML page.
---------
Textbook's website, with examples and example code:
http://www.cadenhead.org/book/21javapre/chapter26.jsp
Sun's JSP By Example:
http://java.sun.com/products/jsp/html/jspbasics.fm.html
---------------------
Some general notes:
HTML markup | JSPs are a solution when you have static HTML content (for non-programmers to update) along with dynamic content from a Java servlet. With JSP, you can change the static HTML without having to recompile the Java servlet. |
calls to Java servlets | |
Java expressions and statements | scriptlets, which are statements between the <% and
%> tags
declaratons, which are statements between the <%! and %> tags |
JSP variables |
JSP Tutorial:
http://www.apl.jhu.edu/~hall/java/Servlet-Tutorial/Servlet-Tutorial-JSP.html
Textbook's website, with examples and example code:
http://www.cadenhead.org/book/21javapre/chapter27.jsp
p. 667, 2nd bullet: Create a servlet that stores the contents of data entered in a form into a file.
______________
course
homepage course
calendar