Get display name from web.xml

I am trying to get the display name (Context Root) from the web.xml file to avoid hard-coding the context root.

Any help would be appreciated.

+5
source share
3 answers

ServletContext.getServletContextName()

Returns the name of this network. the application corresponding to this ServletContext, as specified in the deployment descriptor for this network application using the display name of the element.

+10
source

- . " " " ". <display-name> web.xml, . <Context path> context.xml, ServletContext#getContextPath(). " " ( URL-, ).

+10

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 inside the servlet

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

All Articles