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.
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.
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 .
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.
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With