欧美成人午夜免费全部完,亚洲午夜福利精品久久,а√最新版在线天堂,另类亚洲综合区图片小说区,亚洲欧美日韩精品色xxx

扣丁學(xué)堂Java培訓(xùn)之獲取服務(wù)器基本信息

2019-03-18 14:38:19 7546瀏覽

今天扣丁學(xué)堂Java培訓(xùn)老師給大家分享一篇關(guān)于java獲取服務(wù)器基本信息,文中通過示例代碼介紹的非常詳細(xì),下面我們一起來看一下吧。



實(shí)現(xiàn)步驟:

(1)創(chuàng)建servletBrowserServer

(2)調(diào)用HttpServletRequest對(duì)象的getServerName()方法獲取服務(wù)器名稱

(3)調(diào)用HttpServletRequest對(duì)象的getServerPort()方法獲取服務(wù)器端口

(4)首先調(diào)用getServletContext()方法獲取ServletContext對(duì)象,然后調(diào)用ServletContext對(duì)象的getServerInfo()方法獲取服務(wù)器環(huán)境信息名稱、版本信息

(5)利用HttpServletResponse對(duì)象的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);
  }
 
}

以上就是關(guān)于扣丁學(xué)堂Java培訓(xùn)之獲取服務(wù)器基本信息詳解整合,希望對(duì)大家有所幫助,

最后想要了解更多Java方面內(nèi)容的小伙伴可以登錄扣丁學(xué)堂官網(wǎng)咨詢,扣丁學(xué)堂有專業(yè)老師制定的Java學(xué)習(xí)路線圖輔助學(xué)員學(xué)習(xí),此外還有與時(shí)俱進(jìn)的Java視頻教程供大家學(xué)習(xí)哦,想要學(xué)好Java開發(fā)技術(shù)的同學(xué)請(qǐng)加入扣丁學(xué)堂Java技術(shù)交流群:670348138。


扣丁學(xué)堂微信公眾號(hào)

【關(guān)注微信公眾號(hào)獲取更多學(xué)習(xí)資料】



查看更多關(guān)于“Java開發(fā)資訊”的相關(guān)文章>>

標(biāo)簽: Java培訓(xùn) Java視頻教程 Java多線程 Java面試題 Java學(xué)習(xí)視頻 Java開發(fā)

熱門專區(qū)

暫無熱門資訊

課程推薦

微信
微博
15311698296

全國免費(fèi)咨詢熱線

郵箱:codingke@1000phone.com

官方群:148715490

北京千鋒互聯(lián)科技有限公司版權(quán)所有   北京市海淀區(qū)寶盛北里西區(qū)28號(hào)中關(guān)村智誠科創(chuàng)大廈4層
京ICP備2021002079號(hào)-2   Copyright ? 2017 - 2022
返回頂部 返回頂部