servlet作为tomcat 7中的welcome-file-list

时间:2011-04-11 16:38:54

标签: tomcat servlets

我正在尝试将一个servlet(非jsp)作为我在tomcat 7中的welcome文件,我唯一能做到的就是

将其映射到“/”url-pattern,否则如果我尝试访问该网址,则返回404,即http://url/webapp/

阅读servlet 2.4规范,它允许servlet在欢迎文件列表中,为什么我必须将它映射到“/”url-pattern才能使它工作?

<servlet>
<servlet-name>credentialServlet</servlet-name>
<servlet-class>com.servlet.CredentialServlet</servlet-class>
</servlet>

<servlet-mapping>
    <servlet-name>credentialServlet</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>

<welcome-file-list>
    <welcome-file>credentialServlet</welcome-file>
</welcome-file-list>   

1 个答案:

答案 0 :(得分:8)

我不知道您尝试过哪些网址格式,但在/credentialServlet/credentialServlet/*上映射servlet肯定会有效。

<servlet>
    <servlet-name>credentialServlet</servlet-name>
    <servlet-class>com.servlet.CredentialServlet</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>credentialServlet</servlet-name>
    <url-pattern>/credentialServlet</url-pattern>
</servlet-mapping>

<welcome-file-list>
    <welcome-file>credentialServlet</welcome-file>
</welcome-file-list>