我是Servlet编程的新手。我尝试在网络浏览器上打印特定的东西。
我的项目控制器位于com.myokg.controller文件夹下。这是我的Servlet代码
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Servlet implementation class AddPassenger
*/
@WebServlet("/AddPassenger")
public class AddPassenger extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public AddPassenger() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
response.getWriter().append("Served at: ").append(request.getContextPath());
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doGet(request, response);
}
}
当我输入网址为http://localhost:8080/web1/AddPassenger
时,网络浏览器显示HTTP Status 404 - Not Found
错误。这是为什么?我的路由出错了吗?
修改
文件夹结构
我也试过Servlet returns "HTTP Status 404 The requested resource (/servlet) is not available"这个。但它也不起作用