日期:2014-05-18  浏览次数:20590 次

编写第一个Servlet报错
package pack1;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.Servlet;
import javax.servlet.ServletException;
import javax.servlet.GenericServlet;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import java.util.Date;
//@WebServlet("/hello")
public class test extends GenericServlet{
   public void service(ServletRequest request,ServiceResponse response)
          throws ServletException,IOException{
         response.setContentType("text/html;charset=utf-8");
         PrintWriter out=response.getWriter();
         out.println("<html>");
         out.println("<head><title>欢迎光临</title></head>");
         out.println("<body>");
         out.println("我的第一个Servlet源程序");
         out.println("<br>");
         out.println(new Date());
         out.println("</body>");
         out.println("</html>");
         out.flush();
         out.close();
   }

@Override
public void service(ServletRequest arg0, ServletResponse arg1)
throws ServletException, IOException {
// TODO Auto-generated method stub

}
}

程序12行ServiceResponse报错:ServiceResponse cannot be resolved to a type
第一次学Servlet,求解答???

------解决方案--------------------
12行改成:public?void?service(ServletRequest?request,ServletResponse?response)
------解决方案--------------------
你写了2个service方法,删掉第2个
public void service(ServletRequest request,ServiceResponse response)
红色部分改成ServletResponse
------解决方案--------------------

public class HelloWorld extends HttpServlet
{

    private static final long serialVersionUID = 1L;
    
    public void doGet(HttpServletRequest req, HttpServletResponse res)
        throws IOException, ServletException {