"Hello, World!" Java Extension

This code snippet illustrates how to send a response to an HTTP request from a Java Extension.

Hello, World!

public void doGet( HttpServletRequest req, HttpServletResponse res )
   throws ServletException, IOException
{
   res.setContentType( "text/html" );

   PrintWriter out = res.getWriter();
   out.println( "<h1>Hello, world!</h1>");
}

When you obtain the PrintWriter from the ServletResponse object in a Java Servlet, you indicate your intention to provide a response. If your servlet then completes without writing any data on the PrintWriter, ZXTM will return an empty response to the client.

If you run this code from a request rule, all subsequent rules processing will terminate and the response will be sent directly back to the client.

If you run this code from a response rule, it will modify the response data that was provided by the back-end server. Subsequent response rules will be run, and if they try to inspect the response data, they will see the response that was set by this code.

Running the code

See the Overview article, which describes how to create a Java source file from this code snippet.

The Watermarking article describes how to compile and deploy an extension using an IDE like Eclipse, and the Java Development Guide contains a complete reference.

Owen Garrett [Zeus Dev Team] 01 July 2008  Permalink  
Leave a comment ...
Your email address will not be displayed.
Your URL will be displayed.
This public messageboard is not a forum for technical support. To report technical support problems, please contact our dedicated Support team using the instructions at the bottom of this page.
Options:
 
(Line breaks become <br />)
(Set cookies for name, email & url)
Download Free ZXTM Desktop Edition

Recent Articles

Other Resources



www.zeus.com