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

7 comments:

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

Chris Hemsworth said...

I have been reading for the past two days about your blogs and topics, still on fetching! Wondering about your words on each line was massively effective. Techno-based information has been fetched in each of your topics. Sure it will enhance and fill the queries of the public needs. Feeling so glad about your article. Thanks…!
best software testing training in chennai
best software testing training institute in chennai with placement
software testing training
courses

software testing training and placement
software testing training online
software testing class
software testing classes in chennai
best software testing courses in chennai
automation testing courses in chennai

priya said...

I have been reading for the past two days about your blogs and topics, still on fetching! Wondering about your words on each line was massively effective.
php online training in chennai
php programming center in chennai
php class in chennnai
php certification course
php developer training institution chennai
php training in chennnai
php mysql course in chennai
php institute in chennnai
php course in chennnai
php training with placement in chennnai
php developer course

Anurag Srivastava said...

It’s interesting content and Great work....Most of the part want to analyze their individual scores in the exam. In this process of checking your Exam Latest Result, We support you by giving the Result links to get you All India Sarkari Result in an easy way.

Devi.Angularjs said...

Great Article
Cloud Computing Projects


Networking Projects

Final Year Projects for CSE


JavaScript Training in Chennai

JavaScript Training in Chennai

The Angular Training covers a wide range of topics including Components, Angular Directives, Angular Services, Pipes, security fundamentals, Routing, and Angular programmability. The new Angular TRaining will lay the foundation you need to specialise in Single Page Application developer. Angular Training

James Williams said...

Great Post, Thanks for sharing the information.
PHP Online Training
PHP Online Course
PHP Online Training in chennai

KITS ONLINE TRAINING said...

sap bw on hana training
sap sd training
osb training
oracle scm training
abinitio training
spark training

Blog Archive

Total Pageviews

© BipinRupadiya.com. Powered by Blogger.