This question already has answers here:
Error: “<Class> is not abstract and does not override abstract method <method>”
(3个答案)
2年前关闭。
这是我的代码
当我尝试对其进行编译时:
我想我已经重写了GenericServlet的
(3个答案)
2年前关闭。
这是我的代码
public class hi extends GenericServlet{
public void init(ServletConfig parm1){
}
@Override
public void service(ServletRequest req,ServletRequest res){
PrintWriter pw = res.getWriter();
pw.println("hi");
}
}
当我尝试对其进行编译时:
hi.java:16: error: hi is not abstract and does not override abstract method service(ServletRequest,ServletResponse) in GenericServlet
public class hi extends GenericServlet{
^
hi.java:21: error: method does not override or implement a method from a supertype
@Override
^
hi.java:23: error: cannot find symbol
PrintWriter pw = res.getWriter();
^
symbol: method getWriter()
location: variable res of type ServletRequest
3 errors
我想我已经重写了GenericServlet的
service
方法,但是编译器确实做到了,让我非常困惑... 最佳答案
服务方法的第二个参数应为ServletResponse
关于java - 如何重写GenericServlet? ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/49710390/
10-10 03:14