Home arrow Java Servlets arrow Servlet to view Browser Information while visiting a site in HTML format Friday, 05 December 2008
Home
- - - - - - -
Contact me!
My Blog!
- - - - - - -
- - - - - - -
8086 Assembly Programs
Graphics
Java Servlets
Prolog
VHDL
- - - - - - -
Ubuntu Linux
- - - - - - -
Links
Statistics
Visitors: 43309

   
Servlet to view Browser Information while visiting a site in HTML format
Written by Rohit   
Monday, 10 April 2006

View Demo

  1. /*
  2. * ShowStore.java
  3. *
  4. */
  5. package proteus.SmallFiles;
  6. import java.io.*;
  7. import java.util.*;
  8. import javax.servlet.*;
  9. import javax.servlet.http.*;
  10. /**
  11. *
  12. * @author Rohit
  13. * @version
  14. */
  15. public class ShowStore extends HttpServlet {
  16.     public void init(ServletConfig config) throws ServletException {
  17.     super.init(config);}
  18.     public void destroy() {
  19.     }
  20.     protected void processRequest(HttpServletRequest request, HttpServletResponse response)
  21.     throws ServletException, IOException {
  22.         response.setContentType("text/html");
  23.         PrintWriter out = response.getWriter();
  24.         HttpSession s=request.getSession(true);
  25.         out.println( "<html>" );
  26.         String h;
  27.         try {
  28.             for (Enumeration e=request.getHeaderNames(); e.hasMoreElements() ;)
  29.             if (e==null)
  30.             break;
  31.             else
  32.             {
  33.                 h=(String)e.nextElement();
  34.                 out.println("<b>"+h+"</b> : "+request.getHeader(h)+"<p>");
  35.             }
  36.             out.println("<b>Remote Address</b> : "+request.getRemoteAddr()+"<p>");
  37.             out.println("<b>Remote Host</b> : "+request.getRemoteHost()+"<p>");
  38.             out.println("<b>Server Name</b> : "+request.getServerName()+"<p>");
  39.             out.println("<b>Protocol</b> : "+request.getProtocol()+"<p>");
  40.         }
  41.         catch (java.lang.Exception ex) {
  42.             out.println( "** Error ** " );
  43.             ex.printStackTrace(out);
  44.         }
  45.         out.println( "</html>" );
  46.         out.close();
  47.     }
  48.     protected void doGet(HttpServletRequest request, HttpServletResponse response)
  49.     throws ServletException, IOException {
  50.         processRequest(request, response);
  51.     }
  52.     protected void doPost(HttpServletRequest request, HttpServletResponse response)
  53.     throws ServletException, IOException {
  54.         processRequest(request, response);
  55.     }
  56.     public String getServletInfo() {
  57.         return "The servlet displays HTTP headers!";
  58.     }
  59. }
 
< Prev   Next >

 

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.