我正在尝试将servlet(non-jsp)作为tomcat 7中的欢迎文件,而我能做到的唯一方法是
通过将其映射到“ /” URL模式,否则如果我尝试访问URL(即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>
我不知道大家都尝试过哪种URL模式,但是将servlet映射到/credentialServlet或/credentialServlet/*绝对可以运行。
/credentialServlet
/credentialServlet/*
<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>