// Copyright MageLang Institute; Version $Id: //depot/main/src/edu/modules/Servlets/magercises/DatePrintServlet/solution/DatePrintServlet.java#2 $ import java.io.*; import java.util.*; import java.text.*; import javax.servlet.*; import javax.servlet.http.*; /** * DatePrint Servlet * * The DatePrint Servlet demonstrates how to * generate HTML that will be used in-line in * a page via server-side includes. */ public class DatePrintServlet extends HttpServlet { public void service ( HttpServletRequest req, HttpServletResponse res ) throws ServletException, IOException { String sToday; Date today; ServletOutputStream out; // Get today's date and format it today = new Date(); sToday = DateFormat.getDateInstance().format( today ); // Add one line to // Set the Output Stream to text/plain // Add one line to // Get a handle to the OutputStream going back to the client // Add one line to send the formatted // date to the output stream. // Note: use print and not println // as this is meant to be an in-line // text stream to the browser. } public String getServletInfo() { return "Returns an in-line formatted representation of the current date"; } }