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

創(chuàng)新互聯(lián)是專業(yè)的南開網(wǎng)站建設(shè)公司,南開接單;提供成都網(wǎng)站制作、成都網(wǎng)站建設(shè),網(wǎng)頁(yè)設(shè)計(jì),網(wǎng)站設(shè)計(jì),建網(wǎng)站,PHP網(wǎng)站建設(shè)等專業(yè)做網(wǎng)站服務(wù);采用PHP框架,可快速的進(jìn)行南開網(wǎng)站開發(fā)網(wǎng)頁(yè)制作和功能擴(kuò)展;專業(yè)做搜索引擎喜愛的網(wǎng)站,專業(yè)的做網(wǎng)站團(tuán)隊(duì),希望更多企業(yè)前來(lái)合作!
(1)創(chuàng)建servlet BrowserServer
(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將信息顯示到頁(yè)面
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("<h4>服務(wù)器名稱:"+request.getServerName()+"</h4>");
out.println("<h4>服務(wù)器端口:"+request.getServerPort()+"</h4>");
out.println("<h4>"+context.getServerInfo()+"</h4>");
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ù)器基本信息詳解整合,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)創(chuàng)新互聯(lián)網(wǎng)站的支持!
網(wǎng)頁(yè)題目:淺談java獲取服務(wù)器基本信息
轉(zhuǎn)載源于:http://www.chinadenli.net/article6/isjgog.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站改版、搜索引擎優(yōu)化、網(wǎng)站建設(shè)、網(wǎng)站設(shè)計(jì)公司、定制網(wǎng)站、App設(shè)計(jì)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)