Java HttpServletResponse write message

Description

Java HttpServletResponse write message


import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet(name = "Main", urlPatterns = { "/Main" })
public class Main extends HttpServlet {

   @Override//w w w . j  a  v  a  2  s .co  m
   public void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException {

      res.setContentType("text/html");

      PrintWriter out = res.getWriter();

      out.println("<html><head>");
      out.println("<title>Simple Servlet</title>");
      out.println("</head>");
      out.println("<body>");

      out.println("<p>This is another simple servlet to show you how "
            + "to deploy without listing the servlet within the " + "web-xml configuration file.</p>");

      out.println("</body></html>");

      out.close();
   }
}



PreviousNext

Related