我在网址“http://game.appspot.com/”上有应用程序。我需要从这个基本根调用一个servlet,这意味着调用servlet的相对路径应该是“/”,但是当我这样做时它不起作用:
<url-pattern>/</url-pattern>
在我的 web.xml 文件中,我不能将其留空,例如:
<url-pattern></url-pattern>
因为当我尝试将其部署到 Google 应用引擎时出现错误。
我该怎么办?
谢谢!
最佳答案
似乎有一种较旧的方法可以通过欢迎文件 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>
如果您使用 index.html
,您需要在磁盘上有 index.html
,即使是一个 0 字节的文件,以便 servlet 能够获取被执行。我建议将 url-pattern 设置为其他文件扩展名,也许是 *.xyz,然后在与您的 servlet 关联的磁盘上有一个 0 字节的 index.xyz(我还没有测试过,但它应该 工作)。
关于web.xml 中网站基页的 url 模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13656719/