2008-11-05 63 views
1

我目前正在開發一個WebSphere 6.1 Web項目。如何獲得Websphere 6.1的端口號

在我的java代碼中,如何獲取當前正在運行的應用程序端口?

+0

你是什麼意思與應用端口?你的意思是http端口,就像80,8080端口一樣... – 2008-11-05 10:48:16

回答

3

servlet API爲您提供HttpServletRequest中的本地端口。

protected void doGet(HttpServletRequest request, 
     HttpServletResponse response) throws ServletException, IOException { 
    PrintWriter writer = response.getWriter(); 
    writer.write("" + request.getLocalPort()); 
    writer.close(); 
} 

這些端口在節點的serverindex.xml定義(例如,[WAS] /profiles/AppSrv01/config/cells/localhostNode01Cell/nodes/localhostNode01/serverindex.xml)。

<specialEndpoints xmi:id="NamedEndPoint_1214751102556" endPointName="WC_defaulthost"> 
    <endPoint xmi:id="EndPoint_1214751102556" host="*" port="9080"/> 

我不確定WAS JMX支持是否公開此信息 - 您必須檢查文檔。