FirstServlet.java
package com.servlet.learning;
import java.io.*;
import javax.servlet.*;
class FirstServlet implements Servlet {
ServletConfig config = null;
public void init(ServletConfig config) {
this.config = config;
System.out.println("servlet is initialized");
}
public void service(ServletRequest req, ServletResponse res)
throws ServletException, IOException {
res.setContentType("text/html");
PrintWriter out = res.getWriter();
out.print("<html><body>");
out.print("<b>hello simple servlet</b>");
out.print("</body></html>");
}
public void destroy() {
System.out.println("servlet is destroyed");
}
public ServletConfig getServletConfig() {
return config;
}
public String getServletInfo() {
return "copyright 2007-1010";
}
}
的web.xml
<web-app>
<servlet>
<servlet-name>FirstServlet</servlet-name>
<servlet-class>FirstServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>FirstServlet</servlet-name>
<url-pattern>/FirstServlet</url-pattern>
</servlet-mapping>
</web-app>
1.解决此错误的解决方案是什么
2.设置所有环境变量(JAVA_HOME,PATH,CLASSPATH)
3.执行程序的需要解决方案是Eclipse IDE。
答案 0 :(得分:0)
确保您的servlet类对
不可见<servlet-class>FirstServlet</servlet-class>
你需要改变
<servlet-class>com.servlet.learning.FirstServlet</servlet-class>