在Java中获取Application Server名称或ip和端口 [英] Get Application Server name or ip and port in Java

查看:1311
本文介绍了在Java中获取Application Server名称或ip和端口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们希望识别并显示代理Web服务器后面运行的Java应用程序的服务器和端口。这意味着getServerName()和getServerPort()返回代理的服务器名称及其端口(80)。

We would like to identify and display the server and port that a Java application is running on that is behind a proxy web server. This means that getServerName() and getServerPort() return the server name of the proxy and its port (80).

我们在一个物理上运行两个应用服务器实例框,因此每个框有两个活动端口,即9080,9081。我想要的是< Application Server Name>:< Application Server Port> 显示。

We have two application server instances running on a single physical box and therefore have two active ports per box i.e. 9080, 9081. What I'd like to have is <Application Server Name>:<Application Server Port> displayed.

任何想法?我是一个完整的Java菜鸟,对不起,如果这是一个基本问题。

Any ideas? I'm a complete Java noob, sorry if this is a basic question.

推荐答案

你可以使用 ServletRequest#getLocalXXX()此方法。

  • ServletRequest#getLocalName() returns local hostname.
  • ServletRequest#getLocalAddr() returns local IP.
  • ServletRequest#getLocalPort() returns local port.

这篇关于在Java中获取Application Server名称或ip和端口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆