如何用Jsp/servlet获取客户端浏览器类型?

arlibaba 2001-08-28 04:25:06
各位高人,多多指教!
...全文
135 点赞 收藏 4
写回复
4 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
phil21 2002-02-05
关注
回复
bigking 2002-02-05
关注
回复
johns 2001-08-29
up
回复
wyzegg 2001-08-28
<%--
作者:何志强[hhzqq@21cn.com]
日期:2000-09-19
版本:1.1
功能:JSP例程 - 获取各种CGI环境变量
--%>

<%@ 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>

回复
相关推荐
发帖
Web 开发
创建于2007-09-28

8.0w+

社区成员

Java Web 开发
申请成为版主
帖子事件
创建了帖子
2001-08-28 04:25
社区公告
暂无公告