请教tomcat6.0中servlet的配置问题!
新手学习JSP,使用清华大学出版社出版的《Servlet与JSP核心编程》第2版
JDK是jdk-1_5_0_04-windows-i586-p.exe
TOMCAT是apache-tomcat-6.0.13.exe
JDK的安装目录是E:\Java\jdk1.5.0_04
TOMCAT的安装目录是E:\Tomcat 6.0
环境变量:
PATH
E:\Java\jdk1.5.0_04\bin;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem
classpath
.;E:\Java\jdk1.5.0_04\lib\dt.jar;E:\Java\jdk1.5.0_04\lib\tools.jar;E:\Tomcat 6.0\lib\servlet-api.jar;
CATALINA_HOME
E:\Tomcat 6.0
在E:\Tomcat 6.0\webapps\ROOT目录下,编写Hello.html和Hello.jsp,测试通过。
在E:\Tomcat 6.0\webapps\ROOT\WEB-INF\classes目录下,编写HelloServlet.java
代码如下:
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
/** Simple servlet used to test server.
* <P>
* Taken from Core Servlets and JavaServer Pages 2nd Edition
* from Prentice Hall and Sun Microsystems Press,
* http://www.coreservlets.com/.
* © 2003 Marty Hall; may be freely used or adapted.
*/
public class HelloServlet extends HttpServlet {
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws
ServletException,
IOException {
response.setContentType( "text/html ");
PrintWriter out = response.getWriter();
String docType =
" <!DOCTYPE HTML PUBLIC \ "-//W3C//DTD HTML 4.0 " +
"Transitional//EN\ "> \n ";
out.println(docType +
" <HTML> \n " +
" <HEAD> <TITLE> Hello </TITLE> </HEAD> \n " +
" <BODY BGCOLOR=\ "#FDF5E6\ "> \n " +
" <H1> Hello </H1> \n " +
" </BODY> </HTML> ");
}
}
编译成HelloServlet.class后在IE里执行http://localhost/servlet/HelloServlet
被告示HTTP Status 404 错误,书上说是classpath设置不对
望对servlet