index.html 没有为我的 WebApp 显示(Eclipse 中的 Tomcat 7)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14444681/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 19:50:06  来源:igfitidea点击:

index.html not displaying for my WebApp (Tomcat 7 in Eclipse)

eclipsetomcatweb.xml

提问by Neilos

I have Tomcat 7 with Servlet 3.0 running in Eclipse.

我在 Eclipse 中运行了带有 Servlet 3.0 的 Tomcat 7。

Under my WEB-INF folder I placed two files, web.xml and index.html. The web.xml defines the welcome-file as index.html however when I go to

在我的 WEB-INF 文件夹下,我放置了两个文件,web.xml 和 index.html。web.xml 将欢迎文件定义为 index.html 但是当我去

http://localhost:8080/WebApp/

I get a 404.

我得到一个 404。

Strange thing is that I have a servlet defined as /login and when I go to

奇怪的是,我有一个定义为 /login 的 servlet,当我去

http://localhost:8080/WebApp/login

I can see and use the servlet (I can debug it and see my doGet() request)

我可以查看和使用 servlet(我可以调试它并查看我的 doGet() 请求)

I have no idea why I cannot see the welcome file, It did work a while ago but I have made some changes since then, I changed how I connect to a database by setting up a Connection Pool as Tomcat starts but this shouldn't have affected much. Not quite sure where to look next, catalina.out gives no hints.

我不知道为什么我看不到欢迎文件,它在不久前确实有效,但从那时起我做了一些更改,我通过在 Tomcat 启动时设置连接池来更改连接到数据库的方式,但这不应该影响很大。不太确定下一步该往哪里看,catalina.out 没有给出任何提示。

Can anyone see why my welcome file is not functioning as I want? Any help appreciated :)

任何人都可以看到为什么我的欢迎文件没有按我想要的方式运行?任何帮助表示赞赏:)

回答by Neilos

Ahh my last comment just made me realise something. I was being a bit silly. I simply had my index.html in the wrong location, it shouldn't be under WEB-INF but under WebContent (the parent directory of WEB-INF). The 404 was in fact the massive hint, everything was working correctly except me! Doh!

啊,我的最后一条评论让我意识到了一些事情。我说的有点傻。我只是将我的 index.html 放在错误的位置,它不应该在 WEB-INF 下,而是在 WebContent(WEB-INF 的父目录)下。404 实际上是一个巨大的提示,除了我之外,一切正常!呸!

回答by Rafael Companhoni

In your web.xml file you should have something like this :

在您的 web.xml 文件中,您应该有这样的内容:

<servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.xhtml</url-pattern>
    <url-pattern>*.jsf</url-pattern>
    <url-pattern>/faces/*</url-pattern>
</servlet-mapping>

This way you're mapping url patterns to servlets. In this example, you access index.xhtml, index.jsf or .../faces/index

这样您就可以将 url 模式映射到 servlet。在本例中,您访问 index.xhtml、index.jsf 或 .../faces/index