7

I am trying to have a servlet (non-jsp) as my welcome-file in tomcat 7, and the only way I can do it is

by having it mapped to "/" url-pattern, otherwise it returns 404 not found if i try to access the url i.e. http://url/webapp/

Reading servlet 2.4 specs, it allows servlet in the welcome file list, why do I have to map it to "/" url-pattern to get it working?

<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>   
Lydon Ch
  • 8,637
  • 20
  • 79
  • 132

1 Answers1

8

I don't know what URL patterns you all tried, but mapping the servlet on /credentialServlet or /credentialServlet/* should definitely work.

<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>  
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • ok this does work. I swear i tried this before and it didn't work :P something to do with failed hot-deploy i guessed – Lydon Ch Apr 11 '11 at 17:47
  • 1
    +1. I should've learned already to questions even what the OP claims to be true.. :) – Bozho Apr 11 '11 at 20:27
  • @portoalet: Tomcat doesn't hotdeploy web.xml changes. You really need to restart the thing. @Bozho: You're welcome. – BalusC Apr 11 '11 at 20:30