我试图使用 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
请让我知道我在哪里做错了。