LoginServlet3.java:
package db;import java.io.IOException;
import java.io.PrintWriter;import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;public class LoginServlet3 extends HttpServlet { /**
 * Constructor of the object.
 */
public LoginServlet3() {
super();
} /**
 * Destruction of the servlet. <br>
 */
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
} /**
 * The doGet method of the servlet. <br>
 *
 * This method is called when a form has its tag value method equals to get.
 * 
 * @param request the request send by the client to the server
 * @param response the response send by the server to the client
 * @throws ServletException if an error occurred
 * @throws IOException if an error occurred
 */
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException { response.setContentType("text/html");
PrintWriter out = response.getWriter();
out
.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
out.println("<HTML>");
out.println("  <HEAD><TITLE>A Servlet</TITLE></HEAD>");
out.println("  <BODY>");
out.print("    This is ");
out.print(this.getClass());
out.println(", using the GET method");
out.println("  </BODY>");
out.println("</HTML>");
out.flush();
out.close();
} /**
 * The doPost method of the servlet. <br>
 *
 * This method is called when a form has its tag value method equals to post.
 * 
 * @param request the request send by the client to the server
 * @param response the response send by the server to the client
 * @throws ServletException if an error occurred
 * @throws IOException if an error occurred
 */
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException { response.setContentType("text/html");
PrintWriter out = response.getWriter();
out
.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
out.println("<HTML>");
out.println("  <HEAD><TITLE>A Servlet</TITLE></HEAD>");
out.println("  <BODY>");
out.print("    This is ");
out.print(this.getClass());
out.println(", using the POST method");
out.println("  </BODY>");
out.println("</HTML>");
out.flush();
out.close();
} /**
 * Initialization of the servlet. <br>
 *
 * @throws ServletException if an error occure
 */
public void init() throws ServletException {
// Put your code here
}}

解决方案 »

  1.   

    提示你少包了,你把servlet-api.jar包放到你的lib目录下,进行引用即可
      

  2.   

    但我新建了个web project,按上述方法做的时候就没这个问题
    这是为什么呢?
    你说的这个lib目录是哪个目录呢?能具体点吗?
      

  3.   

    D:\Program Files\Apache Software Foundation\Tomcat 5.5\common\lib
    存在servlet-api.jar这个包
      

  4.   

    ......
    当然tomcat下肯定是有这个包,这样你在jsp页面上就能引用相关的方法了,但是你在servlet里面引用的时候,还需把这个包copy到你的WEB-INF/lib目录下
      

  5.   

    是这个包的问题吗?
    我把servlet-api.jar拷到我的WEB-INF/lib下了.还是有同上面的异常啊
    而且我看下了那个新建的(正常显示的)WEB-INF/lib下可没这个包呢