使用注释无效的Servlet映射

时间:2015-10-12 12:36:19

标签: servlets http-status-code-404

我正在尝试使用注释进行servlet映射,但它无法正常工作。在过去,我已经设法使用一些试验和错误使servlet映射工作,但我真的不想这样做,不再是。

这是放置的s​​ervlet。

|
|src
    |abc.cde.fgh
            |SearchDatabase.java

这是我在SearchDatabase.java中添加的注释 @WebServlet("/pages/SearchDatabase")

通过GET调用servlet时,我得到了404(Not Found) http://localhost:8080/MyProject/pages/SearchDatabase?term=1

这是我最初没有使用的web.xml,因为我没有要求。我读到要使用@WebServlet注释,我需要有一个web.xml。

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://java.sun.com/xml/ns/javaee"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
    version="3.0">
    <display-name>MyProject</display-name>
</web-app>

请解释我做错了什么。

0 个答案:

没有答案
相关问题