LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 778|回复: 2

编译servlet出错,帮助啊!(好像是找不到包的问题)

[复制链接]
发表于 2005-4-23 20:55:31 | 显示全部楼层 |阅读模式
Test.java源代码如下:
package test;
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 Test extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
PrintWriter out=response.getWriter();
out.println("<html><body><h1>This is a servlet test.</h1></body></html>");
out.flush();
}
}

编译错误如下:
E:\tomdep\WEB-INF\classes\test>javac Test.java
Test.java:4: package javax.servlet does not exist
import javax.servlet.ServletException;
                     ^
Test.java:5: package javax.servlet.http does not exist
import javax.servlet.http.HttpServlet;
                          ^
Test.java:6: package javax.servlet.http does not exist
import javax.servlet.http.HttpServletRequest;
                          ^
Test.java:7: package javax.servlet.http does not exist
import javax.servlet.http.HttpServletResponse;
                          ^
Test.java:8: cannot resolve symbol
symbol  : class HttpServlet
location: class test.Test
public class Test extends HttpServlet {
                          ^
Test.java:9: cannot resolve symbol
symbol  : class HttpServletRequest
location: class test.Test
protected void doGet(HttpServletRequest request, HttpServletResponse response)
                     ^
Test.java:9: cannot resolve symbol
symbol  : class HttpServletResponse
location: class test.Test
protected void doGet(HttpServletRequest request, HttpServletResponse response)
                                                 ^
Test.java:10: cannot resolve symbol
symbol  : class ServletException
location: class test.Test
throws ServletException, IOException {
       ^
8 errors

E:\tomdep\WEB-INF\classes\test>
 楼主| 发表于 2005-4-23 21:15:03 | 显示全部楼层
已解决,把servlet-api.jar(tomcat中含有这个包)加入到CLASSPATH中就可以了。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2005-4-23 21:21:50 | 显示全部楼层
我的CLASSPATH如下设置就可以了:
E:\tomdep\WEB-INF\classes\test>echo %classpath%
.;C:\Borland\JBuilder2005\jdk1.4\lib;C:\Borland\JBuilder2005\jdk1.4\jre\lib;C:\B
orland\JBuilder2005\thirdparty\jakarta-tomcat-5.0.27\common\lib\servlet-api.jar
可是我很奇怪,为什么设置CLASSPATH为...\lib\(即servlet-api.jar所在的路径,而不是本类包)就不可以了呢?
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表