当我尝试编译以下java代码时,我收到错误“找不到javax.servlet包”

时间:2011-06-21 08:23:27

标签: java servlets classpath

我在尝试编译以下源代码时找不到错误javax.servlet。*包:

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;

public class servlet1 extends HttpServer
{
public void doPOST(HttpServletRequest req , HttpServletResponse res) throws ServletException,IOException

{
String uid = req.getParameter("T1");
String pwd = req.getParameter("T2");

PrintWriter pw=res.getWriter();
pw.println(uid);
pw.println(pwd);


}
}

我正在使用java 6.0和tomcat 6.0软件

请告诉我如何成功编译此文件?

2 个答案:

答案 0 :(得分:3)

将servlet.jar或j2ee.jar添加到类路径时,必须修复doPost签名。它应该是doPost,而不是doPOST

答案 1 :(得分:0)

您需要Classpath中的Java EE Jars。您可以在app-server(tomcat,glassfish等)的lib目录中找到它们

http://download.oracle.com/javaee/6/api/overview-summary.html