获取request header

example 1

<%@ page import="java.util.*" %>
<%
Enumeration enumNames;
String strName,strValue;
enumNames = request.getHeaderNames();
while(enumNames.hasMoreElements()){
strName = (String)enumNames.nextElement();
strValue = request.getHeader(strName);
%>
<%=strName%><br/><%=strValue%><hr/>
<%}%>


example2


<%--
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
errorPage="ErrorPage.jsp"
import="java.io.*"
import="java.util.*"
%>

<%
Enumeration enames;
Map map;
String title;

// Print the request headers

map = new TreeMap();
enames = request.getHeaderNames();
while (enames.hasMoreElements()) {
String name = (String) enames.nextElement();
String value = request.getHeader(name);
map.put(name, value);
}
out.println(createTable(map, "Request Headers"));

// Print the session attributes

map = new TreeMap();
enames = session.getAttributeNames();
while (enames.hasMoreElements()) {
String name = (String) enames.nextElement();
String value = "" + session.getAttribute(name);
map.put(name, value);
}
out.println(createTable(map, "Session Attributes"));

%>

<%-- Define a method to create an HTML table --%>

<%!
private static String createTable(Map map, String title)
{
StringBuffer sb = new StringBuffer();

// Generate the header lines

sb.append("<table border='1' cellpadding='3'>");
sb.append("<tr>");
sb.append("<th colspan='2'>");
sb.append(title);
sb.append("</th>");
sb.append("</tr>");

// Generate the table rows

Iterator imap = map.entrySet().iterator();
while (imap.hasNext()) {
Map.Entry entry = (Map.Entry) imap.next();
String key = (String) entry.getKey();
String value = (String) entry.getValue();
sb.append("<tr>");
sb.append("<td>");
sb.append(key);
sb.append("</td>");
sb.append("<td>");
sb.append(value);
sb.append("</td>");
sb.append("</tr>");
}

// Generate the footer lines

sb.append("</table><p></p>");

// Return the generated HTML

return sb.toString();
}
%>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值