·您的位置: 首页 » 资源教程 » 编程开发 » JAVA、JSP » JSP例程-获取各种CGI环境变量

JSP例程-获取各种CGI环境变量

类别: JSP教程  评论数:0 总得分:0
<%@ page session="false" import="java.util.*" %>

<%
String strEnvs[][] =
{
{"CONTENT_LENGTH",String.valueOf(request.getContentLength())},
{"CONTENT_TYPE",request.getContentType()},
{"SERVER_PROTOCOL",request.getProtocol()},
{"SERVER_SOFTWARE",getServletContext().getServerInfo()},
{"REMOTE_ADDR",request.getRemoteAddr()},
{"REMOTE_HOST",request.getRemoteHost()},
{"REMOTE_USER",request.getRemoteUser()},
{"SERVER_NAME",request.getServerName()},
{"SERVER_PORT",String.valueOf(request.getServerPort())},
{"AUTH_TYPE",request.getAuthType()},
{"REQUEST_METHOD",request.getMethod()},
{"PATH_INFO",request.getPathInfo()},
{"PATH_TRANSLATED",request.getPathTranslated()},
{"QUERY_STRING",request.getQueryString()},
{"REQUEST_URI",request.getRequestURI()},
{"SCRIPT_NAME",request.getServletPath()},
{"DOCUMENT_ROOT",getServletContext().getRealPath("/")}
};
Enumeration enumNames;
String strName,strValue;
int i;
%>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>JSP例程 - 获取各种CGI环境变量</title>
</head>
<body>
<table border=1 cellspacing=0 cellpadding=0 align=center>
<tr>
<th>Name</th>
<th>Value</th>
</tr>
<%
enumNames = request.getHeaderNames();
while(enumNames.hasMoreElements()){
strName = (String)enumNames.nextElement();
strValue = request.getHeader(strName);
%>
<tr>
<td> <%=strName%></td>
<td> <%=strValue%></td>
</tr>
<%
}
%>
<tr>
<th>Name</th>
<th>Value</th>
</tr>
<%
for(i=0;i<strEnvs.length;i++){
%>
<tr>
<td> <%=strEnvs[i][0]%></td>
<td> <%=strEnvs[i][1]%></td>
</tr>
<%
}
%>
</table>
</body>
</html>
-= 资 源 教 程 =-
文 章 搜 索
关键词:
类型:
范围:
纯粹空间 softpure.com
Copyright © 2006-2008 暖阳制作 版权所有
QQ: 15242663 (拒绝闲聊)  Email: faisun@sina.com
 纯粹空间 - 韩国酷站|酷站欣赏|教程大全|资源下载|免费博客|美女壁纸|设计素材|技术论坛   Valid XHTML 1.0 Transitional
百度搜索 谷歌搜索 Alexa搜索 | 粤ICP备19116064号-1