06年德国对阿根廷:test.java编译失败

来源:百度文库 编辑:高考问答 时间:2024/05/02 05:54:58
我在配置TOMCAT时候,经过一个编译test.java的过程。
importjava.io.IOException;
importjava.io.PrintWriter;
importjavax.servlet.ServletException;
importjavax.servlet.http.HttpServlet;
importjavax.servlet.http.HttpServletRequest;
importjavax.servlet.http.HttpServletResponse;
publicclassTestextendsHttpServlet{
protectedvoiddoGet(HttpServletRequestrequest,HttpServletResponseresponse)
throwsServletException,IOException{
PrintWriterout=response.getWriter();
out.println("
Thisisaservlettest.
");
out.flush();
}
}

为什么总是报错??请高手指点。我TOMCAT我没配起来。

楼上的不对 !
继承了HttpServlet 不需要重写 其他的方法

1. 修改为:
public void doGet

2。没有设置 servlet-api.jar 的 classpath 路径 !
(j2se是不包括 servlet 类的)

这是个Servlet,所以必须重写public void init() throws ServletException方法
public void doGet(HttpServletRequestrequest,HttpServletResponseresponse)
throwsServletException,IOException方法
还有public void destory()方法

另外你的doGet方法的访问权限写错了,应该为public ,否则线程无法访问该service服务