JSP擷取用戶端的瀏覽器和作業系統資訊

來源:互聯網
上載者:User

  string agent = request.getheader("user-agent");

  stringtokenizer st = new stringtokenizer(agent,";");

  st.nexttoken();

  //得到使用者的瀏覽器名

  string userbrowser = st.nexttoken();

  //得到使用者的作業系統名

  string useros = st.nexttoken();

  取得原生資訊也可以這樣:

  作業系統資訊

  system.getproperty("os.name"); //win2003竟然是win xp?

  system.getproperty("os.version");

  system.getproperty("os.arch");

  瀏覽器:

  request.getheader(“user-agent”)返回用戶端瀏覽器的版本號碼、類型

  getheader(string name):獲得http協議定義的傳送檔案頭資訊,

  request. getmethod():獲得用戶端向伺服器端傳送資料的方法有get、post、put等類型

  request. getrequesturi():獲得發出請求字串的用戶端地址

  request. getservletpath():獲得用戶端所請求的指令檔的檔案路徑

  request. getservername():獲得伺服器的名字

  request.getserverport():獲得伺服器的連接埠號碼

  request.getremoteaddr():獲得用戶端的ip地址

  request.getremotehost():獲得用戶端電腦的名字,若失敗,則返回用戶端電腦的ip地址

  request.getprotocol():

  request.getheadernames():返回所有request header的名字,結果集是一個enumeration(枚舉)類的執行個體

  request.getheaders(string name):返回指定名字的request header的所有值,結果集是一個enumeration(枚舉)類的執行個體



相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.