package examples.htmlkona; import java.io.*; import javax.servlet.*; import javax.servlet.http.*; import weblogic.html.*; /** * This example demonstrates the creation of a simple servlet * with htmlKona that displays an HTML page when invoked from * a Java-enabled server. This page displays "Hello world!" *

* To run this example, edit the defaults.java file to set * local environment names and variables. Then compile * this directory, register the servlets in your T3Server's * weblogic.properties file, and use a URL to * invoke the servlet. There are more instructions on setting * up the WebLogic Server as an HTTP server and registering servlets * in the WebLogic Server Administrator's Guide, * Setting * up the WebLogic Server as an HTTP server * * @author Copyright (c) 1996-98 by WebLogic, Inc. All Rights Reserved. * @author Copyright (c) 1999 by BEA WebXpress. All Rights Reserved. */ public class HelloWorld extends HttpServlet { /** * The service method is where the real work is done in a * HTTP servlet. In this method, we set the page type, * and then construct the page with htmlKona components. Finally, we * call the output() method with the results of the * HttpServletResponse.getOutputStream() method. * * @param req HttpServletRequest object * @param res HttpServletResponse object * @exception java.io.IOException if there is a transfer error */ public synchronized void service(HttpServletRequest req, HttpServletResponse res) throws IOException { try { res.setStatus(HttpServletResponse.SC_OK); res.setContentType("text/html"); StringElement caption = new StringElement("Hello World!"); ServletPage hp = new ServletPage(); hp.getHead() .addElement(new TitleElement("HelloWorld")); hp.getBodyElement() .setAttribute(BodyElement.bgColor, HtmlColor.white); hp.getBody() .addElement(MarkupElement.HorizontalLine) .addElement(caption.asBoldElement()) .addElement(MarkupElement.HorizontalLine) .addElement(new StringElement("Copyright 1996-99 by BEA WebXpress, Inc.") .asFontElement(-1)); hp.output(res.getOutputStream()); } catch (Exception e) { defaults.showException(e, res.getOutputStream()); } } }