我剛剛學寫了servlet程序如下:
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.http.*;
import javax.servlet.*;
public class MyServlet extends HttpServlet{
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
// HttpServletRequest 請求類,封裝所有的請求信息
// HttpServletResponse 響應類
//super.doGet(req, resp);
PrintWriter out = resp.getWriter();
out.print("Hello Servlet!");
out.close();
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
// TODO Auto-generated method stub
//super.doPost(req, resp);
}
}
運行後拋出異常如下:
java.lang.ClassNotFoundException: org.apache.catalina.startup.Catalina
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
網上有說是tomcat的配置問題,關於我的tomcat設置,見如下圖片:
不知道是哪出問題了,請大神幫忙看一下,剛剛接觸MyEclipse和Tomcat。或者是不是其他地方的問題?
1、你在web.xml中有沒有配置好該Servlet類?
2、Tomcat啟動是否成功,看看你控制台的啟動信息,如果控制台啟動有錯誤的話那就是Tomcat配置錯了