postheadericon 11. Write a Servlet to display all the headers available from request.


import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;
import javax.servlet.annotation.WebServlet;

/** Showing all request headers of current request. */

@WebServlet(
name="WTAD",
urlPatterns={"/Ex11","/bipinrupadiya.blogspot.com","/RequestHeaders"}
)
public class ShowRequestHeaders extends HttpServlet {
  public void doGet(HttpServletRequest request,HttpServletResponse response)
      throws ServletException, IOException
{
    response.setContentType("text/html");
    PrintWriter out = response.getWriter();
    String title = "GTU : Ex-11 : Showing all Request Headers";
    out.println("<HTML>\n" +
                "<HEAD><TITLE>" + title + "</TITLE></HEAD>\n" +
                "<BODY BGCOLOR=\"#FDF5E6\">\n" +
                "<H1 ALIGN=\"CENTER\">" + title + "</H1>\n" +
                "<B>Request Method: </B>" +
                request.getMethod() + "<BR>\n" +
                "<B>Request URI: </B>" +
                request.getRequestURI() + "<BR>\n" +
                "<B>Request Protocol: </B>" +
                request.getProtocol() + "<BR><BR>\n" +
                "<TABLE BORDER=1 ALIGN=\"CENTER\">\n" +
                "<TR BGCOLOR=\"#FFAD00\">\n" +
                "<TH>Header Name<TH>Header Value");
    Enumeration headerNames = request.getHeaderNames();
    while(headerNames.hasMoreElements()) {
      String headerName = (String)headerNames.nextElement();
      out.println("<TR><TD>" + headerName);
      out.println("    <TD>" + request.getHeader(headerName));
    }
    out.println("</TABLE>\n</BODY></HTML>");
  }


  public void doPost(HttpServletRequest request,HttpServletResponse response)
      throws ServletException, IOException {
    doGet(request, response);
  }
}

output

3 comments:

velraj said...

This is an important article. I read like this type of article only. You mentioned more important points about technology. Thankyou.
core java training in chennai
Best core java Training in Chennai
core java Training in OMR
C Training in Chennai
javascript training in chennai
Appium Training in Chennai
JMeter Training in Chennai
core java training in chennai

Sivanandhana Girish said...

Thanks for your efforts in sharing this information in detail. This was very helpful to me. kindly keep continuing the great work.
Spoken English Classes in Chennai
Best Spoken English Classes in Chennai
IELTS Coaching in Chennai
IELTS Coaching Centre in Chennai
English Speaking Classes in Mumbai
English Speaking Course in Mumbai
IELTS Classes in Mumbai
IELTS Coaching in Mumbai

dhivya said...

I would definitely thank the admin of this blog for sharing this information with us. Waiting for more updates from this blog admin.
Machine Learning course in Chennai
Machine Learning Training in Chennai
Azure Training in Chennai
Cloud Computing Training in Chennai
RPA Training in Chennai
UiPath Training in Chennai

Follow by Email

Blog Archive

Total Pageviews

© BipinRupadiya.com. Powered by Blogger.