service() method in Servlet life cycle

 In order to display the output in browser, we need to below 3 steps in service() method 

                // 1. Set the response type to HTML

response.setContentType("text/html");


// 2. Use PrintWriter object  to send the response

PrintWriter out = response.getWriter();

out.println("<html><head><title>Output</title></head>");

out.println("<body>");

out.println("<h1 style='color:red'><marquee>Welcome to servlet coding...</marquee></h1>");

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

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


// 3. Close the PrintWriter

out.close();

Comments

Popular posts from this blog

Advantages and Disadvantages of Monolithic Architecture

Monolithic Architecture

Eclipse debugging