Hire Our Expert Programmer & Technical Writer To Do Your Capstone Project
+1 vote
in Programming Languages & Algorithms by

1 Answer

+1 vote
by (user.guest)
selected by (user.guest)
 
Best answer
package mypkg;

 

import java.io.*;

import javax.servlet.*;

import javax.servlet.http.*;

 

public class Servlet extends HttpServlet {

   @Override

   public void doGet(HttpServletRequest request, HttpServletResponse response)

               throws IOException, ServletException {

      response.setContentType("text/html;charset=UTF-8");

      // Allocate a output writer to write the response message into the network socket

      PrintWriter out = response.getWriter();

      // Write the response message, in an HTML page

      try {

         out.println("<!DOCTYPE html>");

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

         out.println("<meta http-equiv='Content-Type' content='text/html; charset=UTF-8'>");

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

         out.println("<body>");

         out.println("<h1>Name!</h1>");

         out.println("<h2>Age!</h2>");

         out.println("<h3>Qualification!</h3>");

         out.println("<p>Request URI: " + request.getRequestURI() + "</p>");

         out.println("<p>Protocol: " + request.getProtocol() + "</p>");

         out.println("<p>PathInfo: " + request.getPathInfo() + "</p>");

         out.println("<p>Remote Address: " + request.getRemoteAddr() + "</p>");

         // Generate a random number upon each request

         out.println("<p>A Random Number: <strong>" + Math.random() + "</strong></p>");

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

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

      } finally {

         out.close();  // Always close the output writer

Related questions

+1 vote
1 answer
Welcome to CPENTalk.com

Disclaimer: Every user is solely responsible for anything that he/she posts or uploads on CPENTalk.
...