web.xml中站点基页的url-pattern

mic*_*l_u 5 url design-patterns web.xml servlets

我在url"http://game.appspot.com/"上有应用程序.我需要从这个基本根调用一个servlet,这意味着调用servlet的相对路径应该是"/",但是当我这样做时它不起作用:

<url-pattern>/</url-pattern>
Run Code Online (Sandbox Code Playgroud)

在我的web.xml文件中,我不能把它留空:

<url-pattern></url-pattern>
Run Code Online (Sandbox Code Playgroud)

因为当我尝试将其部署到谷歌应用引擎时出现错误.

我该怎么办?

谢谢!

cfe*_*uke 2

似乎有一种较旧的方法可以通过欢迎文件 servlet hack 来实现此目的:

来自http://www.coderanch.com/t/359995/Servlets/java/Servlets-Mapping-root-path-exclusively

<servlet>
  <description></description>
  <display-name>test</display-name>
  <servlet-name>test</servlet-name>
  <servlet-class>Test</servlet-class>
</servlet>

<servlet-mapping>
  <servlet-name>test</servlet-name>
  <url-pattern>*.html</url-pattern>
</servlet-mapping>

<welcome-file-list>
  <welcome-file>index.html</welcome-file>
</welcome-file-list>
Run Code Online (Sandbox Code Playgroud)

如果您使用,index.html则需要将其保存index.html在磁盘上,即使是 0 字节文件,以便执行 servlet。我建议将 url-pattern 设置为其他文件扩展名,也许是 *.xyz,然后在与您的 servlet 关联的磁盘上有一个 0 字节的 index.xyz(我还没有测试过,但它应该可以工作)。