Over a million developers have joined DZone.

Minimal Java Servlet

·
There is nothing particularly original here -- there are variations of this all over the place. This works nicely with my JettyLauncher class (see my other posts on DZone Snippets).



package com.babblemind;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

public class HelloWorldServlet extends HttpServlet{
    protected void doGet(HttpServletRequest httpServletRequest,
	HttpServletResponse httpServletResponse)
	    throws ServletException, IOException {

        httpServletResponse.setContentType("text/plain");
        PrintWriter out = httpServletResponse.getWriter();
        out.println("Hello World!");
        out.close();
    }
}
Topics:

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}