Technical Support
Discussion Forum
Online Training
Technical Articles
Bug Parade
JDC Resources
DukeDollars
Early Access Toolbar

Java Cup Logo
java.sun.com


Solaris Developer Connection

JDC Home Page

Log Out

Online Training
shadowSearchFAQFeedback

Training Index

Fundamentals of JavaTM Servlets: Magercises
Generating In-line Content

By MageLang Institute

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

Prerequisites

Skeleton Code

In this Magercise you build a servlet that generates output to be used in-line, inside a web page. An important difference between this type of servlet and those that generate complete HTML responses is that the output MIME type must be "text/plain" and not "text/html".

The servlet is activated via a special servlet tag that is supported by the Java Web ServerTM. This may not be available on any other server, be sure to check your server's documentation.

The servlet tag has the form:

    <servlet code="ServletName">
    </servlet>

Perform the following tasks:

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

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

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

  4. Compile the servlet.

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

  6. Request the service from a browser by clicking here.

The task numbers above are linked to the step-by-step help page. Also available is a complete solution to the problem, and a demonstration of the expected behavior.

When you finish this Magercise you will understand how to write servlets that provide in-line content generation.

Copyright © 1998 MageLang Institute. All Rights Reserved.





Questions?
8-Jan-99
Copyright © 1996-1998 Sun Microsystems Inc.
All Rights Reserved. Legal Terms. Privacy Policy.
Sun Logo