Java Servlet映射。欢迎文件列表

时间:2012-11-04 19:04:10

标签: java web.xml

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

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

映射到此

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

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

http://localhost:8086/gmustudent/index

然而,这给了我一个404

http://localhost:8086/gmustudent/

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

1 个答案:

答案 0 :(得分:18)

     http://localhost:8086/gmustudent/

gmustudent是webapplication的上下文根。 index是您想要访问的resource

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

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

访问

  http://localhost:8086/gmustudent/
相关问题