当前位置: 技术问答>java相关
帮帮我,我学习的第一个简单的SERVLET程序运行报错
来源: 互联网 发布时间:2015-11-09
本文导语: 我的运行环境win98、TOMCAT、JCreator,servlet程序如下 class t extends HttpServlet{ public void doGet(HttpServletRequest request,HttpServletResponse response) throws IOException ,ServletException { response.setContentType("text/html"); ...
我的运行环境win98、TOMCAT、JCreator,servlet程序如下
class t extends HttpServlet{
public void doGet(HttpServletRequest request,HttpServletResponse response)
throws IOException ,ServletException
{
response.setContentType("text/html");
PrintWriter out=response.getWriter();
out.println("");
out.println("");
out.println("Hello World!");
out.println("");
out.println("");
out.println("");
out.println("ok");
out.println("");
out.println("");
}
}
运行http://localhost:8080/examples/servlet/t
提示出现以下错误:
javax.servlet.ServletException: Cannot allocate servlet instance for path /examples/servlet/t
at org.apache.catalina.servlets.InvokerServlet.serveRequest(InvokerServlet.java:415)
.....
请问这是什么问题呀?感激不尽!
class t extends HttpServlet{
public void doGet(HttpServletRequest request,HttpServletResponse response)
throws IOException ,ServletException
{
response.setContentType("text/html");
PrintWriter out=response.getWriter();
out.println("");
out.println("");
out.println("Hello World!");
out.println("");
out.println("");
out.println("");
out.println("ok");
out.println("");
out.println("");
}
}
运行http://localhost:8080/examples/servlet/t
提示出现以下错误:
javax.servlet.ServletException: Cannot allocate servlet instance for path /examples/servlet/t
at org.apache.catalina.servlets.InvokerServlet.serveRequest(InvokerServlet.java:415)
.....
请问这是什么问题呀?感激不尽!
|
编译了吗?编译后放在web-inf/classes下
|
import语句写了吗?
另:
class t extends HttpServlet
应该加public在class前
改成public class t extends HttpServlet
另:
class t extends HttpServlet
应该加public在class前
改成public class t extends HttpServlet
|
编译后放在web-inf/classes下,并以http://localhost:8080/servlet/t运行
|
编译后放在web-inf/classes下,别忘了启动tomcat.并以http://localhost:8080/servlet/t运行