Java Sevlet 映射。欢迎文件列表

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13221820/
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-10-31 11:56:07  来源:igfitidea点击:

Java Sevlet Mapping. Welcome File List

javaweb.xml

提问by gmustudent

In my web.xml file I have this

在我的 web.xml 文件中,我有这个

<!-- WELCOME FILE LIST -->
<welcome-file-list>
    <welcome-file>/index</welcome-file>
</welcome-file-list>

Which maps to this

哪个映射到这个

<!-- SERVLET FOR THE HOME PAGE -->
<servlet>
    <servlet-name>HomePageServlet</servlet-name>
    <servlet-class>com.gmustudent.HomePageServlet</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>HomePageServlet</servlet-name>
    <url-pattern>/index</url-pattern>
</servlet-mapping>

When I put this in the address bar I get my home page site and the servlet grabs all of my content as requested.

当我把它放在地址栏中时,我得到了我的主页站点,servlet 根据请求抓取了我的所有内容。

http://localhost:8086/gmustudent/index

However, this gives me a 404

但是,这给了我一个 404

http://localhost:8086/gmustudent/

Why isn't my welcome file list grabbing that welcome file servlet when index is not explicitly stated?

为什么我的欢迎文件列表没有在没有明确说明索引时抓取那个欢迎文件 servlet?

回答by PermGenError

     http://localhost:8086/gmustudent/

gmustudent is the context root of your webapplication. index is the resourceyou wanna access.

gmustudent 是您的 web 应用程序的上下文根。索引是resource你想要访问的。

you configure welcome file like below, remove the prepending / :

您配置如下欢迎文件,删除前置 / :

<welcome-file>Index</welcome-file> 
</welcome-file-list> 

to access

访问

  http://localhost:8086/gmustudent/