欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

java获取客服端信息的方法(系统,浏览器等)

程序员文章站 2024-03-12 17:22:02
如下所示: string agent = request.getheader("user-agent"); system.out.println(agent)...

如下所示:

string agent = request.getheader("user-agent"); 
system.out.println(agent); 
stringtokenizer st = new stringtokenizer(agent,";"); 
st.nexttoken(); 
string userbrowser = st.nexttoken(); 
system.out.println(userbrowser); 
string useros = st.nexttoken(); 
system.out.println(useros); 
system.out.println(system.getproperty("os.name")); //win2003竟然是win xp? 
system.out.println(system.getproperty("os.version")); 
system.out.println(system.getproperty("os.arch")); 
system.out.println(request.getheader("user-agent")); //返回客户端浏览器的版本号、类型 
system.out.println(request.getmethod()); //:获得客户端向服务器端传送数据的方法有get、post、put等类型 
system.out.println(request.getrequesturi()); //:获得发出请求字符串的客户端地址 
system.out.println(request.getservletpath()); //:获得客户端所请求的脚本文件的文件路径 
system.out.println(request.getservername()); //:获得服务器的名字 
system.out.println(request.getserverport()); //:获得服务器的端口号 
system.out.println(request.getremoteaddr()); //:获得客户端的ip地址 
system.out.println(request.getremotehost()); //:获得客户端电脑的名字,若失败,则返回客户端电脑的ip地址
system.out.println(request.getprotocol()); //: 
system.out.println(request.getheadernames()); //:返回所有request header的名字,结果集是一个enumeration(枚举)类的实例 
system.out.println("protocol: " + request.getprotocol()); 
system.out.println("scheme: " + request.getscheme()); 
system.out.println("server name: " + request.getservername() ); 
system.out.println("server port: " + request.getserverport()); 
system.out.println("protocol: " + request.getprotocol()); 
system.out.println("server info: " + getservletconfig().getservletcontext().getserverinfo()); 
system.out.println("remote addr: " + request.getremoteaddr()); 
system.out.println("remote host: " + request.getremotehost()); 
system.out.println("character encoding: " + request.getcharacterencoding()); 
system.out.println("content length: " + request.getcontentlength()); 
system.out.println("content type: "+ request.getcontenttype()); 
system.out.println("auth type: " + request.getauthtype()); 
system.out.println("http method: " + request.getmethod()); 
system.out.println("path info: " + request.getpathinfo()); 
system.out.println("path trans: " + request.getpathtranslated()); 
system.out.println("query string: " + request.getquerystring()); 
system.out.println("remote user: " + request.getremoteuser()); 
system.out.println("session id: " + request.getrequestedsessionid()); 
system.out.println("request uri: " + request.getrequesturi()); 
system.out.println("servlet path: " + request.getservletpath()); 
system.out.println("accept: " + request.getheader("accept")); 
system.out.println("host: " + request.getheader("host")); 
system.out.println("referer : " + request.getheader("referer")); 
system.out.println("accept-language : " + request.getheader("accept-language")); 
system.out.println("accept-encoding : " + request.getheader("accept-encoding")); 
system.out.println("user-agent : " + request.getheader("user-agent")); 
system.out.println("connection : " + request.getheader("connection")); 
system.out.println("cookie : " + request.getheader("cookie"));

获得user-agent的值

在 asp.net 中使用 request.header["user-agent"] 得到浏览器的 user agent,也可以使用 request.useragent 来获取;

java 中使用 request.getheader(”user-agent”) 来获得;

php 中相应使用:$_server[http_user_agent];

js中则使用navigator.useragent来获得(客户端经常使用它来做浏览器兼容)。

以上就是小编为大家带来的java获取客服端信息的方法(系统,浏览器等)的全部内容了,希望对大家有所帮助,多多支持~