Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get display name from web.xml file

Tags:

java

servlets

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.

like image 607
Sunny Avatar asked Jul 06 '10 15:07

Sunny


People also ask

What is display name in Web XML?

The optional display-name element specifies the Web application display name, a short name that can be displayed by GUI tools. Currently, this element is not used by WebLogic Server.

How to define JSP in web XML?

jsp is compiled into a servlet class automatically, and mapped to the URL path equivalent to the path to the JSP file from the WAR root. For example, if an app has a JSP file named start. jsp in a subdirectory named register/ in its WAR, App Engine compiles it and maps it to the URL path /register/start. jsp .

How does web XML work in java?

web. xml defines mappings between URL paths and the servlets that handle requests with those paths. The web server uses this configuration to identify the servlet to handle a given request and call the class method that corresponds to the request method.


2 Answers

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.

like image 111
skaffman Avatar answered Sep 22 '22 18:09

skaffman


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

like image 22
BalusC Avatar answered Sep 23 '22 18:09

BalusC