有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java如何为未配置web的web应用指定显示名称。xml

如何为仅使用WebApplicationInitializer在java中编程配置的web应用程序(war)指定显示名称。我有类似的东西

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

web.xml这个看起来像这样:

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

这在Java配置中可能吗


共 (1) 个答案

  1. # 1 楼答案

    ServletContext接口不提供更改显示名称的方法。还有其他一些事情它也不允许你做。在这些情况下,必须使用部署描述符,即web.xml

    注意,它有一个^{}方法

    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.