PlaintextServlet.java 519 B

123456789101112131415161718
  1. package hello;
  2. import java.io.*;
  3. import java.nio.charset.Charset;
  4. import javax.servlet.*;
  5. import javax.servlet.http.*;
  6. public class PlaintextServlet extends HttpServlet {
  7. private static final Charset utf8 = Charset.forName("UTF-8");
  8. private static final byte[] HELLO_WORLD = "Hello, World!".getBytes(utf8);
  9. @Override
  10. protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
  11. res.setContentType("text/plain");
  12. res.getOutputStream().write(HELLO_WORLD);
  13. }
  14. }