我目前正在对WebSphere 6.1 Web项目。
在我的Java代码,我怎样才能得到当前运行的应用程序端口?
我目前正在对WebSphere 6.1 Web项目。
在我的Java代码,我怎样才能得到当前运行的应用程序端口?
该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公开此信息 - 你不得不检查文档。
如果你使用RAD你可以从IDE运行管理控制台,然后发现通过使用了所有端口
http://pic.dhe.ibm.com/infocenter/radhelp/v9/index.jsp?topic=%2Fcom.ibm.sca.tools.doc%2Fsamples%2Ftopics%2Fwas_ports.html