Fundamentals of JavaTM Servlets: Magercises
Help: Generating In-line Content

By MageLang Institute

[Help | Solution | API Docs | Expected Output | Course Notes | Magercises | Module Intro]

Help is available for each task, or you can go straight to the solution source code.

Task 1

Add a line of code to set the output stream MIME type to "text/plain".

Add the code:

res.setContentType("text/plain");

Task 2

Add a line of code to get a reference to the output stream being sent back to the client.

Add the code:

out = res.getOutputStream();

Task 3

Add a line of code to send the formatted date to the output stream.

Add the code:

out.print(sToday);

Task 4

Compile the servlet.

javac *.java

Task 5

Copy the servlet and the file DatePrintServeltDemo.shtml to location where the Java Web Server can use them.

A batch file copyit is included in the solution subdirectory to copy these files to the proper locations.

Task 6

Request the service from a browser by clicking here.

Enter the URL

http://localhost:8080/DatePrintServletDemo.shtml
and observe the display in the browser.

Copyright © 1998 MageLang Institute. All Rights Reserved.