欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

淺談java獲取服務(wù)器基本信息

 更新時間:2019年03月18日 11:53:12   作者:小鷹展翅  
這篇文章主要介紹了java獲取服務(wù)器基本信息,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧

實現(xiàn)步驟:

(1)創(chuàng)建servlet BrowserServer
(2)調(diào)用HttpServletRequest對象的getServerName()方法獲取服務(wù)器名稱
(3)調(diào)用HttpServletRequest對象的getServerPort()方法獲取服務(wù)器端口
(4)首先調(diào)用getServletContext()方法獲取ServletContext對象,然后調(diào)用ServletContext對象的getServerInfo()方法獲取服務(wù)器環(huán)境信息名稱、版本信息
(5)利用HttpServletResponse對象的PrintWriter將信息顯示到頁面

package example.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class BrowserServer
 */
@WebServlet("/BrowserServer")
public class BrowserServer extends HttpServlet {
  private static final long serialVersionUID = 1L;
    
  
  protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    response.setContentType("text/html;charset=utf-8");
    PrintWriter out=response.getWriter();
    ServletContext context=getServletContext();
    
    out.println("<html>");
    out.println("<head>");
    out.println("<title>服務(wù)器信息</title>");
    out.println("</head>");
    out.println("<body>");
    out.println("<h3>服務(wù)器名稱:"+request.getServerName()+"</h3>");
    out.println("<h3>服務(wù)器端口:"+request.getServerPort()+"</h3>");
    out.println("<h3>"+context.getServerInfo()+"</h3>");
    out.println("</body>");
    out.println("<html>");  
    out.close();
  }


  protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    processRequest(request,response);
  }


  protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    processRequest(request,response);
  }

}

以上所述是小編給大家介紹的java獲取服務(wù)器基本信息詳解整合,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!

相關(guān)文章

  • SpringMvc實現(xiàn)簡易計算器功能

    SpringMvc實現(xiàn)簡易計算器功能

    這篇文章主要為大家詳細(xì)介紹了SpringMvc實現(xiàn)簡易計算器功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-07-07
  • 分布式任務(wù)調(diào)度xxl-job問題解決

    分布式任務(wù)調(diào)度xxl-job問題解決

    這篇文章主要為大家介紹了分布式任務(wù)調(diào)度xxl-job的問題解決,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多多多進(jìn)步,早日升職加薪
    2022-03-03
  • java  BASE64Encoder詳細(xì)介紹及簡單實例

    java BASE64Encoder詳細(xì)介紹及簡單實例

    這篇文章主要介紹了java BASE64Encoder詳細(xì)介紹及簡單實例的相關(guān)資料,需要的朋友可以參考下
    2017-01-01
  • Spring?Boot?3.1中整合Spring?Security和Keycloak的方法

    Spring?Boot?3.1中整合Spring?Security和Keycloak的方法

    本文介紹在最新的SpringBoot3.1版本之下,如何將Keycloak和Spring?Security一起跑起來,文中結(jié)合實例代碼給大家介紹的非常詳細(xì),需要的朋友參考下吧
    2023-06-06
  • 在SpringBoot項目中使用Java8函數(shù)式接口的方法示例

    在SpringBoot項目中使用Java8函數(shù)式接口的方法示例

    在Spring Boot項目中,Java 8 的函數(shù)式接口廣泛用于實現(xiàn)各種功能,如自定義配置、數(shù)據(jù)處理等,函數(shù)式接口在Spring Boot中非常有用,本文展示了在SpringBoot項目中使用Java8的函數(shù)式接口的方法示例,需要的朋友可以參考下
    2024-03-03
  • 關(guān)于feign接口動態(tài)代理源碼解析

    關(guān)于feign接口動態(tài)代理源碼解析

    這篇文章主要介紹了關(guān)于feign接口動態(tài)代理源碼解析,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-03-03
  • Java ArrayList與LinkedList使用方法詳解

    Java ArrayList與LinkedList使用方法詳解

    Java中容器對象主要用來存儲其他對象,根據(jù)實現(xiàn)原理不同,主要有3類常用的容器對象:ArrayList使用數(shù)組結(jié)構(gòu)存儲容器中的元素、LinkedList使用鏈表結(jié)構(gòu)存儲容器中的元素
    2022-11-11
  • JAVA抽象類,接口,內(nèi)部類詳解

    JAVA抽象類,接口,內(nèi)部類詳解

    這篇文章主要給大家介紹了關(guān)于Java中抽象類,接口,內(nèi)部類的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2021-09-09
  • 基于selenium-java封裝chrome、firefox、phantomjs實現(xiàn)爬蟲

    基于selenium-java封裝chrome、firefox、phantomjs實現(xiàn)爬蟲

    這篇文章主要介紹了基于selenium-java封裝chrome、firefox、phantomjs實現(xiàn)爬蟲,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2020-10-10
  • SpringBoot使用Log4j的知識點整理

    SpringBoot使用Log4j的知識點整理

    在本篇文章里小編給大家整理的是關(guān)于SpringBoot使用Log4j的知識點,需要的朋友們可以參考學(xué)習(xí)下。
    2020-02-02

最新評論