I am absolutely new to Java.
I am creating a Servlet and getting the error interface is expected here.
Can you please make me understand the problem(s)?
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 in Advance.
HttpServlet is an abstract class, not an interface - Servlet is an interface, but you rarely implement that directly.
The HttpServletRequest object can be used to retrieve incoming HTTP request headers and form data. The HttpServletResponse object can be used to set the HTTP response headers (e.g., content-type) and the response message body.
The servlet container of a web service is responsible for the creation of a ServletRequest object. The servlet container wraps all data that came from a client to a web server as a request. Also, the servlet container creates a corresponding ServletResponse object, that will be filled with data in a servlet.
You can declare multiple servlets using the same class with different initialization parameters. The name for each servlet must be unique across the deployment descriptor. The <servlet-mapping> element specifies a URL pattern and the name of a declared servlet to use for requests whose URL matches the pattern.
HttpServlet
is an abstract class, not an interface - Servlet
is an interface, but you rarely implement that directly.
Just change this:
public class ErpServlet implements HttpServlet {
to
public class ErpServlet extends HttpServlet {
and you should be fine.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With