|
Java学习者论坛
我都弄了三天了,还是出现同一个错误。两眼都要冒金花了,希望大家来帮我看看,问题到底是出在哪?
要测试的程序代码是(HelloServlet.java):
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
/** Simple servlet used to test server.
* 2<>
* Taken from More Servlets and JavaSErver Pages
* from Prentice Hall and Sun Microsystems Press,
* ? 2002 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文件放到C:\Program Files\Tomcat 5.0\webapps\ROOT\WEB-INF\classes\下,然后修改C:\Program Files\Tomcat 5.0\webapps\ROOT\WEB-INF\web.xml文件为如下所示:
<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
Copyright 2004 The Apache Software Foundation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">
<display-name>Welcome to Tomcat</display-name>
<description>
Welcome to Tomcat
</description>
<!-- JSPC servlet mappings start -->
<servlet>
<servlet-name>HelloServlet</servlet-name>
<servlet-class>HelloServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>HelloServlet</servlet-name>
<url-pattern>/servlet/HelloServlet</url-pattern>
</servlet-mapping>
<!-- JSPC servlet mappings end -->
</web-app>
最后在IE的地址栏输入:http://localhost:8080/servlet/HelloServlet出现如下错误提示:
HTTP Status 404 - /servlet/HelloServlet
type Status report
message /servlet/HelloServlet
description The requested resource (/servlet/HelloServlet) is not available.
Apache Tomcat/5.0.28
而我运行C:\Program Files\Tomcat 5.0\webapps\servlets-examples的文件例子都是正常的,所以我总是找不出我设置的文件错误出在哪里,希望各位朋友指点,多谢!
Java学习者论坛欢迎来到Java学习者论坛,转载请注明地址:http://www.javaxxz.com. |
|