Java Tutorial/JSP/HTTP Header

Материал из Java эксперт
Версия от 17:44, 31 мая 2010; (обсуждение)
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Перейти к: навигация, поиск

Get HTTP Header Information

index.jsp



<HTML>
    <HEAD>
        <TITLE>Getting Header Data</TITLE>
    </HEAD>
 
    <BODY>
        <H1>Getting Header Data</H1>
        <FORM ACTION="basic.jsp" METHOD="POST">
            <INPUT TYPE="submit" VALUE="Submit">
        </FORM>
    </BODY>
</HTML>





Print out HTTP Request Headers

<%--
  Copyright (c) 2002 by Phil Hanna
  All rights reserved.
  
  You may study, use, modify, and distribute this
  software for any purpose provided that this
  copyright notice appears in all copies.
  
  This software is provided without warranty
  either expressed or implied.
--%>
<%@ page import="java.util.*" %>
<html>
   <head>
      <title>Echo</title>
      <style>
      <jsp:include page="style.css" flush="true"/>
      </style>
   </head>
   <body>
      <h1>HTTP Request Headers Received</h1>
      <table border="1" cellpadding="4" cellspacing="0">
      <%
         Enumeration eNames = request.getHeaderNames();
         while (eNames.hasMoreElements()) {
            String name = (String) eNames.nextElement();
            String value = normalize(request.getHeader(name));
      %>
         <tr><td><%= name %></td><td><%= value %></td></tr>
      <%
         }
      %>
      </table>
   </body>
</html>
<%!
   private String normalize(String value)
   {
      StringBuffer sb = new StringBuffer();
      for (int i = 0; i < value.length(); i++) {
         char c = value.charAt(i);
         sb.append(c);
         if (c == ";")
            sb.append("<br>");
      }
      return sb.toString();
   }
%>