簡體   English   中英

在ServletContextListener上獲取Web應用程序ip和端口

[英]Get web application ip and port on ServletContextListener

我想在服務器啟動時獲取我的Web應用程序IP和端口嗎? 例如在我的ServletContextListener類中。 但是我無法使用FaceContext和ServletContextEvent來獲取它們。

FacesContext.getCurrentInstance().getExternalContext().getRequestServerName()

使用上面的代碼將導致不支持的方法。

由於它需要一個從我們的應用程序開始運行的線程,因此我們迫不及待地將某些請求發送到我們的服務器。

我們的應用程序使用jsf2,primeface並在weblogic 10.3.6上運行

您需要像這樣訪問HttpServletRequest:

HttpServletRequest request = ((HttpServletRequest)FacesContext.getCurrentInstance().getExternalContext().getRequest());
request.getLocalAddr();
request.getLocalPort();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM