import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
public class HelloServlet extends HttpServlet {
public void init(ServletConfig config) throws ServletException {
super.init(config);
}
public void service(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
String clientIPAddress = req.getRemoteAddr();
res.setContentType("text/html");
ServletOutputStream out = res.getOutputStream();
out.println("<html>");
out.println("<head><title>Hello World</title></head>");
out.println("<body>");
out.println("<h1>Hello,You come from "+clientIPAddress+"</h1>");
out.println("</body></html>");
}
}
大家看这段代码我在javac时提示说
package javax.servlet does not exist
可是我装jdk1.4和tomcat4了,为什么找不到它呢,但是tomcat带的例子也都导入了这些包,我应该怎么才能编译呢?在线急盼
在电脑中搜索servlet.jar,加入classpath或是放到tomcat/common/lib文件夹中
同意zcjl的意见
tomcat的servlet.jar包就在tomcat/common/lib中,将tomcat/common/lib加进classpath没有?
是呀,把那个servlet包的路径加入classpath中就行了,tomcat/common/lib/servlet.jar。