Java EE获取Servlet容器端口 [英] Java EE getting servlet container port

查看:89
本文介绍了Java EE获取Servlet容器端口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想以编程方式获取部署我的Java EE应用程序的servlet容器端口.我以为JMX bean中会有东西,但是我似乎找不到任何东西.

I want to programmatically get the servlet containers port that my Java EE application is deployed on. I assumed there would be something in the JMX beans but I can't seem to find anything.

在任何人说从HttpRequest或HttpResponse夺取端口之前,应注意该过程在Servlet后面运行,并且与请求或响应没有交互.

And before anyone says grab the port from the HttpRequest or HttpResponse it should be noted that this process is running behind the servlet and has no interaction with the Requests or Responses.

推荐答案

一种可能的破解"是在运行时解析server.xml并标识已配置的端口.

One possible "hack" would be to parse the server.xml at runtime and identify the port that is configured.

但是看起来还有一种使用JMX/MBean的方法.

But looks like there is a way to do it using JMX / MBeans as well.

这篇关于Java EE获取Servlet容器端口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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