WebServlet urlPatterns给出404错误

时间:2013-04-06 21:19:53

标签: servlet-3.0

我试图使用servlet Annotation。

这是我的servlet,如下所示,上下文名称为 Teste 我的项目中没有任何web.xml。

package com;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
@WebServlet(name = "Mine", urlPatterns = { "/Mine" })
public class Mine extends HttpServlet {
    private static final long serialVersionUID = 1L;
    public Mine() {
        super();
        System.out.println("I am Called");
    }

    protected void doGet(HttpServletRequest request,
            HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html");
        PrintWriter out = response.getWriter();
        HttpSession session = request.getSession(true);
        String str = (String) session.getAttribute("salary");
        out.println("str is" + str);
    }
}

当我尝试在浏览器中访问时,我收到错误404

enter image description here

请让我知道我在做错误的地方。

0 个答案:

没有答案