Dave's Brain

Browse - Programming Tips - What does a basic Java servlet look like?

Date: 2013nov22
Language: Java
Keywords: minimal

Q.  What does a basic Java servlet look like?

A.

import javax.servlet.*; import javax.servlet.http.*; public class MyServlet extends HttpServlet { @Override public void init(ServletConfig sconfig) throws ServletException { super.init(sconfig); // Do stuff } @Override public void doGet(HttpServletRequest request_in, HttpServletResponse response) throws ServletException, IOException { PrintWriter out = response.getWriter(); out.println("hello <b>World</b>"); } @Override public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doGet(request, response); } }

Add a comment

Sign in to add a comment
Copyright © 2008-2017, dave - Code samples on Dave's Brain is licensed under the Creative Commons Attribution 2.5 License. However other material, including English text has all rights reserved.