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 {


   public void doGet(HttpServletRequest request, HttpServletResponse response)

               throws IOException, ServletException {


      // 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("<meta http-equiv='Content-Type' content='text/html; charset=UTF-8'>");






         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>");



      } 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.