JSPを使ってクライアント情報を読み取る
JSPを使ってクライアント情報を読み取ります。以下のコードを読んでください。もしあなたの使用要求が違ったら、これらのコードを簡単に修正できます。これらのコードはあなたに獲得できます。会社company、ユーザーname、バージョンversion、main version、minor versionのオペレーティングシステム(未完成!)、ラングゲ、localeなど。新しいJSPファイルを作成します。次のクラスのファイルをclasspathに入れてください。package de.hnsicker.http.util;import java.util.*;import javax.servlet.*;import javax.servlet.http.*;public class Browser extens HttpServlet{protected HttpServletRequest request}protected HttpSessionセッション;protected String userAgent;protected String company//Firmenname des Herstellers protected String name;/Bezechnung des Browsers protected String version;/Version protected String main Version;/Hauptversion protected String minorVersion;//Uterversion protected String os;/Betriebssystem protected String langage=\"de\"Sprachcode Standard protected Locall locale;//Locale-Object mit den aktuellen//Sprachinstellungine prvate Hashtable supported LangugesUnesttzte Sprachen public Browser(HttpServletRequest request,HttpSession session){this.initialize();this.request=request;this.session=session;this.set UserAgent(this.request.get Header);this.setCompany()this.set Name()this.set Version()this.set MainVersion()this.set Minor Verssion()this.setOs()this.set Language()this.set Locale();public void initialize(){this.supported Languags=new Hashtable(2);this.supportedLanguags.put(\"en\"、\");this.supportedLanguags.put(\"de\",\");;。public void set UserAgent{String httpUserAgent}prvate void set Company(){if(this.userAgent.indexOf(\"msie\")>-1){this.com mpany=\"Microsoft\";else if(this.userAgent.indexOf(\"opera\")>-1){this.com mpany=\"Opera Software\";else if(this.userAgent.indexOf(\"mozila\")>-1){this.com mpany=\"Netscape Communication\"else{this.com mpany=\"unknown\"}/*。Liefert den Firmennamen des Herstellers des verwendeten Browsers.*/public String getCompany(){return this.co.mpany}prvate void set Name(){if(this.com mpany=\"Microsoft\"){this.name=\"Microsoft Internet Explorer\"else if(this.com mpany=\"Netscape Communications\"){this.name=\"Netscape Navigator\"else if(this.com mpany=\"Operasoff tware\"){this.name=\"Operasoff tware Opera\"else{this.name=\"unknown\"}/***Liefert den Namen des verwendeten Browsers.*/public String getName(){return this.name}prvate void set Verssion(){int tmpPos;String tmpStringif(this.com mpany=\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 Version snummer des verwendeten Browsers.*/public String get Version(){return this.version}。privte void set MainVerssion(){this.main Version=this.version.substring(0,this.version.indexOf)/*。Liefert die Haup tversions nummer des verwendeten Browsers.*/public String getMainVerssion(){return this.manVersion;}privte void set Minor Verssion(){this.minorVersion=this.version.substring(this.version.indexOf(\.\)+1).trim()/***Liefert die Uterversions nummer des verwendeten Browsers.*/public String get Minor Verssion(){return this.minorVersion}。prvate void setOs(){if(this.userAgent.indexOf(\"win\")>-1){if(this.userAgent.indexOf(\"windows 95\")}-Windows 1|this.userAgent.indexf(\"win")if(this.userAgent.indexOf(\"windows 98\")--1|this.userAgent.indexOf(\"win 98\")--1){this.os=\"Windows 98\"if(this.userAgent.indexOf(\"windows nt\")--1|this.userAgent.indexOf(\"wint\")--1){this.os=\"Windows NT\"if(this.userAgent.indexOf(\"win 16\")--1|this.userAgent.indexOf(\"windows 3.\")--1){this.os=\"Windows 3.x\"、}/****Liefert den Namen des Betriebssystems.*/public String getOs(){return this.os;}prvate void set Language(){String prefLanguage=this.request.get Header];if(prefLanguage!=null){String laggage=null;Stering Tokenizer st=new String Tokenizer(prefLanguage)\int elements=st.com Tokens()for(int idx=0idx elementsidx+){if(this.supported Languags.com ntainsKey){this.langage=st.next Token)}{this.langage=this.parse Locale}Hilfsfunkation fr set Language()*/prvate String parse Locale(String langage){Stering Tokenizer st=new String Tokenizer(lagge);;if(st.com unt Tokens()==2){return st.next Token()}else{return langage;}/***Liefert das L?nderk myzerder vom Benutzur*bevorzugten Sprache.*/public String getLanguage(){return this.lagage}prvate void set Locale(){this.locale=new Locare(this.langgge)}/*。Liefert ein Locale-Object mit der Sprach-Prferenz des verwendeten Browsers*/public Locall get Locall e(){return this.locale;}