O'Reilly logo

Special Edition Using Java™ Server Pages and Servlets by Mark Wutka

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 3. Getting Started with Servlets

A "Hello World" Servlet

Servlets are a little more involved than Java Server Pages, but in simple cases they aren't too bad. Listing 3.1 shows you the "Hello World" program in servlet form.

Example 3.1. Source Code for HelloWorldServlet.java

 package usingjsp; import javax.servlet.*; import java.io.*; public class HelloWorldServlet extends GenericServlet { public void service(ServletRequest request, ServletResponse response) throws IOException { // Tell the Web server that the response is HTML response.setContentType("text/html"); // Get the PrintWriter ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required