Java Servlet Interface expected here

I am completely new to Java.

I create a servlet and get an interface is expected here. error message interface is expected here.

Could you help me understand the problem?

I am using IntelliJ 14.

My servlet code is as follows: -

 package ERPdetector; /** * Created by Sinha on 12/15/14. */ import javax.servlet.http.*; import javax.servlet.*; import java.io.*; public class ErpServlet implements HttpServlet { public void doGet(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException { res.setContentType("text/html"); PrintWriter pw=res.getWriter(); String dropdown=req.getParameter("dropdown"); pw.println("You Requested for "+dropdown); pw.close(); } } 

Thanks at Advance.

+6
source share
5 answers

HttpServlet is an abstract class, not an interface. Servlet is an interface, but you rarely implement it directly.

Just change this:

 public class ErpServlet implements HttpServlet { 

to

 public class ErpServlet extends HttpServlet { 

and everything should be fine.

+6
source

You should use the implements keyword only when implementing the interface , since the HttpServlet is an abstract class , you should use the extends .

Since you are trying to use the implements keyword for the abstract class (HttpServlet), your ID environment is generating an error.

+3
source

HttpServlet is a class that implements Servlet. Thus, you must extend the HttpServlet class, or you need to implement the Servlet interface. And do the Http related stuff manually.

HttpServlet already overrides methods from the Servlet interface. It has doGet, doPost, doPut like methods. If you want to implement the Servlet interface, you need to override the entire interface method and process the HttpServletRequest, HttpServletResponse objects.

+1
source

HTTPServlet not an interface. Please follow this example to make your servlet work.

If you want to use your own implementation of the HTTPServlet class, then create a replica of the original abstract class, that is, implement the intefaces Servlet and ServletConfig , and also extend the GenericServlet .

If you want to use SipServlet , you need to implement the same interfaces as in SipServlet .

+1
source

Implementation → Interface and Extends → Class or Abstract class.

so that you use the tools keyword, not extends. just replace the line below in code.

open class ErpServlet extends HttpServlet

thanks

+1
source

Source: https://habr.com/ru/post/979607/


All Articles