大雀软件园

首页 软件下载 安卓市场 苹果市场 电脑游戏 安卓游戏 文章资讯 驱动下载
技术开发 网页设计 图形图象 数据库 网络媒体 网络安全 站长CLUB 操作系统 媒体动画 安卓相关
当前位置: 首页 -> 技术开发 -> JSP专区 -> 使用JSP读取客户端信息

使用JSP读取客户端信息

时间: 2021-07-31 作者:daque

使用JSP读取客户端信息   请观赏以次代码。即使你的运用诉求各别,可对那些代码加以很简单的窜改。那些代码不妨使你赢得: 公司company, 用户name,本子version,main version,minor version 操纵体例(未实行!),谈话language,locale等。 创造一个新的jsp文献: 请将下列class文献介入classpath (你要创造同样的目次构造-- de.hunsicker.http.util,固然也不妨本人安排包的称呼。!): package de.hunsicker.http.util; import java.util.*; import javax.servlet.*; import javax.servlet.http.*; public class browser extends httpservlet { protected httpservletrequest request; protected httpsession session; protected string useragent; protected string company; // firmenname des herstellers protected string name; // bezeichnung des browsers protected string version; // version protected string mainversion; // hauptversion protected string minorversion; // unterversion protected string os; // betriebssystem protected string language = \"de\"; // sprachcode standard protected locale locale; // locale-objekt mit den aktuellen // spracheinstellungen private hashtable supportedlanguages; // untersttzte sprachen public browser(httpservletrequest request, httpsession session) { this.initialize(); this.request = request; this.session = session; this.setuseragent(this.request.getheader(\"user-agent\")); this.setcompany(); this.setname(); this.setversion(); this.setmainversion(); this.setminorversion(); this.setos(); this.setlanguage(); this.setlocale(); } public void initialize() { this.supportedlanguages = new hashtable(2); this.supportedlanguages.put(\"en\", \"\"); this.supportedlanguages.put(\"de\", \"\"); } public void setuseragent(string httpuseragent) { this.useragent = httpuseragent.tolowercase(); } private void setcompany() { if (this.useragent.indexof(\"msie\") > -1) { this.company = \"microsoft\"; } else if (this.useragent.indexof(\"opera\") > -1) { this.company = \"opera software\"; } else if (this.useragent.indexof(\"mozilla\") > -1) { this.company = \"netscape communications\"; } else { this.company = \"unknown\"; } } /** * liefert den firmennamen des herstellers des verwendeten browsers. */ public string getcompany() { return this.company; } private void setname() { if (this.company == \"microsoft\") { this.name = \"microsoft internet explorer\"; } else if (this.company == \"netscape communications\") { this.name = \"netscape navigator\"; } else if (this.company == \"operasoftware\") { this.name = \"operasoftware opera\"; } else { this.name = \"unknown\"; } } /** * liefert den namen des verwendeten browsers. */ public string getname() { return this.name; } private void setversion() { int tmppos; string tmpstring; if (this.company == \"microsoft\") { string str = this.useragent.substring(this.useragent.indexof(\"msie\") + 5); this.version = str.substring(0, str.indexof(\";\")); } else { tmpstring = (this.useragent.substring(tmppos = (this.useragent.indexof(\"/\")) + 1, tmppos + this.useragent.indexof(\" \"))).trim(); this.version = tmpstring.substring(0, tmpstring.indexof(\" \")); } } /** * liefert die versionsnummer des verwendeten browsers. */ public string getversion() { return this.version; } private void setmainversion() { this.mainversion = this.version.substring(0, this.version.indexof(\".\")); } /** * liefert die hauptversionsnummer des verwendeten browsers. */ public string getmainversion() { return this.mainversion; } private void setminorversion() { this.minorversion = this.version.substring(this.version.indexof(\".\") + 1).trim(); } /** * liefert die unterversionsnummer des verwendeten browsers. */ public string getminorversion() { return this.minorversion; } private void setos() { if (this.useragent.indexof(\"win\") > -1) { if (this.useragent.indexof(\"windows 95\") > -1 || this.useragent.indexof(\"win95\") > -1) { this.os = \"windows 95\"; } if (this.useragent.indexof(\"windows 98\") > -1 || this.useragent.indexof(\"win98\") > -1) { this.os = \"windows 98\"; } if (this.useragent.indexof(\"windows nt\") > -1 || this.useragent.indexof(\"winnt\") > -1) { this.os = \"windows nt\"; } if (this.useragent.indexof(\"win16\") > -1 || this.useragent.indexof(\"windows 3.\") > -1) { this.os = \"windows 3.x\"; } } } /** * liefert den namen des betriebssystems. */ public string getos() { return this.os; } private void setlanguage() { string preflanguage = this.request.getheader(\"accept-language\"); if (preflanguage != null) { string language = null; stringtokenizer st = new stringtokenizer(preflanguage, \",\"); int elements = st.counttokens(); for (int idx = 0; idx elements; idx++) { if (this.supportedlanguages.containskey((language = st.nexttoken()))) { this.language = this.parselocale(language); } } } } /* * hilfsfunktion fr setlanguage(). */ private string parselocale(string language) { stringtokenizer st = new stringtokenizer(language, \"-\"); if (st.counttokens() == 2) { return st.nexttoken(); } else { return language; } } /** * liefert das l?nderkürzel der vom benutzer * bevorzugten sprache. */ public string getlanguage() { return this.language; } private void setlocale() { this.locale = new locale(this.language, \"\"); } /** * liefert ein locale-objekt mit der sprach-prferenz des verwendeten browsers */ public locale getlocale() { return this.locale; } }

热门阅览

最新排行

Copyright © 2019-2021 大雀软件园(www.daque.cn) All Rights Reserved.