O'Reilly logo

Head First Servlets and JSP, 2nd Edition by Bert Bates, Bryan Basham, Kathy Sierra

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Two things the web server alone won’t do

If you need just-in-time pages (dynamically-created pages that don’t exist before the request) and the ability to write/save data on the server (which means writing to a file or database), you can’t rely on the web server alone.

1 Dynamic content

The web server application serves only static pages, but a separate “helper” application that the web server can communicate with can build non-static, just-in-time pages. A dynamic page could be anything from a catalog to a weblog or even just a page that randomly chooses pictures to display.

When instead of this:

Note

<html>
<body>
The current time is
always 4:20 PM
on the server
</body>
</html>

You want this:

Note

<html>
<body>
The current time is
[insertTimeOnServer]
on the server
</body>
</html>

Just-in-time pages don’t exist before the request comes in. It’s like making an HTML page out of thin air.

The request comes in, the helper app “writes” the HTML, and the web server gets it back to the client.

2 Saving data on the server

When the user submits data in a form, the web server sees the form data and thinks, “So? Like I care?”. To process that form data, either to save it to a file or database or even just to use it to generate the response page, you need another app. When the web server sees a request for a helper app, the web server assumes that parameters are meant for that app. So the web server hands over the parameters, and gives the app a way to generate a response to the client.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required