@Override protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { String reqMethod = req.getMethod(); if (reqMethod.equals("GET") || reqMethod.equals("POST")) { super.service(req, resp); } else { resp.setStatus(405); // Method Not Allowed } }