public class UserServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String requestURL = req.getRequestURL().toString();
PrintWriter writer = resp.getWriter();
if(requestURL != null && requestURL.lastIndexOf("/") > 0){
requestURL = requestURL.substring(requestURL.lastIndexOf("/") + 1);
String idStr = req.getParameter("id");
Integer id = Integer.parseInt(idStr);
if("add".equals(requestURL)){
addUser(id);
} else if("delete".equals(requestURL)){
deleteUser(id);
}
writer.write("success");
return;
}
writer.write("url error");
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
super.doPost(req, resp);
}
// 新增方法
private void addUser(Integer id){
System.out.println("addUser-->" + id);
}
// 删除方法
private void deleteUser(Integer id){
System.out.println("deleteUser-->" + id);
}
}