MariuszS
MariuszS

Reputation: 31587

How to specify display name for web app configured without web.xml

How to specify display name for web application (war) configured programmatically in java with WebApplicationInitializer only. I have something like this

public class WebAppInitializer implements WebApplicationInitializer {
  public void onStartup(ServletContext servletContext) throws ServletException {
     ...
  }
}

With web.xml this look like this:

<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
version="3.0" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"    metadata-complete="false">
   <display-name>my app</display-name>
   ...
</web-app>

Is this possible in Java configuration?

Upvotes: 11

Views: 3330

Answers (1)

Sotirios Delimanolis
Sotirios Delimanolis

Reputation: 280030

The ServletContext interface does not provide a method to change the display name. There are some other things that it also doesn't let you do. In those cases, you have to use the deployment descriptor, ie. the web.xml.

Note that it has a getServletContextName() method which

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.

Upvotes: 4

Related Questions