【问题标题】:Is it possible to get the root-context (defined on the web.xml) of an application [duplicate]是否可以获得应用程序的根上下文(在 web.xml 上定义)[重复]
【发布时间】:2019-07-22 03:06:44
【问题描述】:

根上下文示例

   <?xml version="1.0" encoding="UTF-8"?>
    <jboss-web>
        <context-root>/Tesoreria-WEB</context-root>
        <max-active-sessions>300</max-active-sessions>
    </jboss-web>

是否有可能使用带有 primefaces 的 java 中的某些方法获得那个“/TESORIA-WEB”?

我试过了

PrimeRequestContext.getCurrentInstance(FacesContext.getCurrentInstance()).getApplicationContext());

但没有成功,在互联网上找不到关于专门从 web.xml 获取根上下文的信息

【问题讨论】:

  • @BalusC 的这个答案对我有用,谢谢你们stackoverflow.com/questions/46556861/… 所以它基本上是 FacesContext.getCurrentInstance().getExternalContext().getRequestContextPath();得到那个“/Tesoreria-WEB”

标签: jsf web.xml


【解决方案1】:

servletContext.getContextPath()

返回 Web 应用程序的上下文路径。

上下文路径是请求 URI 的一部分,用于选择请求的上下文。上下文路径始终位于请求 URI 的首位。路径以/ 字符开头,但不以/ 字符结尾。对于默认(根)上下文中的 servlet,此方法返回 "".*

httpServletRequest.getContextPath()

返回请求 URI 中指示请求上下文的部分。上下文路径始终位于请求 URI 的首位。路径以“/”字符开头,但不以“/”字符结尾。对于默认(根)上下文中的 servlet,此方法返回“”。容器不解码此字符串。

【讨论】:

猜你喜欢
  • 2011-11-01
  • 1970-01-01
  • 2010-11-23
  • 1970-01-01
  • 2011-08-29
  • 1970-01-01
  • 2018-02-14
  • 2013-02-27
相关资源
最近更新 更多