访问servlet类名或servlet名

时间:2011-03-01 16:09:27

标签: servlets

http://127.0.0.1:8080/testserver

testserver应该是servlet的classname的servlet名称吗?

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>helloTest</display-name>
<servlet>
    <description>
    </description>
    <display-name>foo</display-name>
    <servlet-name>foo</servlet-name>
    <servlet-class>
    foo</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>foo</servlet-name>
    <url-pattern>/foo9</url-pattern>
</servlet-mapping>
<welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
</welcome-file-list>

好的,所以我说

http://127.0.0.1:8080/helloTest/foo9 

它有效,但是当我说

http://127.0.0.1:8080/helloTest/foo

它不起作用为什么会这样?

1 个答案:

答案 0 :(得分:1)

testserver应与<url-pattern>中的<servlet-mapping>相匹配 (或@WebServlet注释的参数)