tags:

views:

41

answers:

2

I am trying to get the Display name (Context Root) from web.xml file to avoid hardcoding a context root.

Any help would be appreciated.

+2  A: 

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.

skaffman
+3  A: 

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).

BalusC