jsp獲取主機地址和主機名
阿新 • • 發佈:2019-02-07
公司運維說要小程式能獲取到主句地址和主機名,後面說一個頁面更簡單,所以簡單記錄一下。
<%@ page language="java" contentType="text/html; charset=utf-8" import="java.net.InetAddress" pageEncoding="utf-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>index.jsp</title> </head> <body> <% InetAddress addr = InetAddress.getLocalHost(); out.println("主機地址:"+addr.getHostAddress()); out.println("主機名:"+addr.getHostName()); %> </body> </html>