开发者

Get display name from web.xml file

I am trying to ge开发者_StackOverflowt the Display name (Context Root) from web.xml file to avoid hardcoding a context root.

Any help would be appreciated.


ServletContext.getServletContextName()

Returns the name of this web application corresponding to this ServletContext as specified in the deployment descriptor for this web application by the display-name element.


There's some ambiguity in your question. The "display name" is not the same as "context root". To get the <display-name> value from web.xml, look at skaffman's answer in this question. To get the <Context path> value from context.xml, use ServletContext#getContextPath(). This is often referenced as "context root" (which you also see in the URL, that part immediately after domain).


En nombre puede obtener de la clase ServletContext. Con JSF

ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
ServletContext servletContext= (ServletContext) externalContext.getContext();
System.out.println("Context Name: "+servletContext.getServletContextName());

Or Within a Servlet

protected void doGet(HttpServletRequest request, HttpServletResponse response)
{
ServletContext servletContext= getServletContext();
System.out.println("Context Name: "+servletContext.getServletContextName());
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜