编译Servlet文件找不到类的问题?
大家好,我初学JSP,今天编译Servlet总是出错,
我把tomcat5.5中的Servlet-api.jar复制到%JAVA_HOME%\jre\lib\ext\中,并设置好了环境变量
JAVA_HOME=C:\Program Files\Java\jdk1.5.0_07
classpath=%JAVA_HOME%\jre\lib\ext\servlet-api.jar;
然后试图用javac编译文件TestServlet.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 TestServlet 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();
}
}
出现以下错误:
C:\> javac TestServlet.java
TestServlet.java:1: 需要 "class " 或 "interface "
锘縫ackage test;
^
TestServlet.java:3: 需要 "class " 或 "interface "
import java.io.IOException;
^
TestServlet.java:4: 需要 "class " 或 "interface "
import java.io.PrintWriter;
^
TestServlet.java:5: 需要 "class " 或 "interface "
import javax.servlet.ServletException;
^
TestServlet.java:6: 需要 "class " 或 "interface "
import javax.servlet.http.HttpServlet;
^
TestServlet.java:7: 需要 "class " 或 "interface "
import javax.servlet.http.HttpServletRequest;
^
TestServlet.java:8: 需要 "class " 或 "interface "
import javax.servlet.http.HttpServletResponse;
^
7 错误
用javac编译其它的.java类文件是没问题的,为什么编译servlet会找不到类呢?究竟要把Servlet-api.jar放在哪里和怎样设置环境变量才行?
------解决方案--------------------看错误提示不是找不到servlet类
classpath里少了当前路径 ". "
------解决方案--------------------classpath中的第一个逗号应该换成句点,在寻变量路径的时候代表当前工作路径