求助,HTTP Status 404错误

bulver 2011-05-22 10:46:17
一个最简单的servlet程序,可是怎么都跑不出来,一直包HTTP Status 404错误,在网上找了很多解决办法都没搞定,求这里的朋友帮忙看下。

HelloWorldServlet.java的代码如下:

package org.bulver.HelloWorld.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.Servlet;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

public class HelloWorldServlet implements Servlet{
private ServletConfig config;
public void destroy(){}

public ServletConfig getServletConfig(){
return config;
}

public String getServletInfo(){
return null;
}

public void init(ServletConfig config) throws ServletException{
this.config = config;
}

public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException{
PrintWriter out = res.getWriter();
out.println("Hello World");
out.close();
}
}



web.xml文件代码如下:

<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You 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_5.xsd"
version="2.5">

<display-name>Welcome to Tomcat</display-name>
<description>
Welcome to Tomcat
</description>

<servlet>
<servlet-name>HelloWorldServlet</servlet-name>
<servlet-class>org.bulver.HelloWorld.servlet.HelloWorldServlet</servlet-class>
</servlet>

<serlvet-mapping>
<servlet-name>HelloWorldServlet</servlet-name>
<url-pattern>/helloworld</url-pattern>
</serlvet-mapping>

</web-app>


class文件放的目录是:D:\WorkSpace\Tomcat 6.0\webapps\HelloWorld\WEB-INF\classes\org\bulver\HelloWorld\servlet

在IE中输入的访问地址是:http://localhost:8080/HelloWorld/helloworld

最后报错:The requested resource (/HelloWorld/helloworld) is not available.

怎么也看不出哪里错了,请大家帮忙看看了。
...全文
208 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
JavaMan 2011-05-23
  • 打赏
  • 举报
回复
首先:
<serlvet-mapping>
<servlet-name>HelloWorldServlet</servlet-name>
<url-pattern>/helloworld</url-pattern>
</serlvet-mapping>

配置信息错误,无法以hellworld访问该servlet。
其次:
public class HelloWorldServlet implements Servlet{
继承的是servlet虽然也可以,但是不是由Http协议实现的Servlet。如果是Web开发,建议继承HttpServlet
wangjintao110 2011-05-23
  • 打赏
  • 举报
回复
这个问题有点难办啊www.cctv40.com 都不能解决。。。。。。。。
qwe065560 2011-05-23
  • 打赏
  • 举报
回复
明显是配置文件中的servlet拼写错误。
追风★少年 2011-05-23
  • 打赏
  • 举报
回复
找不到源文件
tarkhnas 2011-05-23
  • 打赏
  • 举报
回复
你配置文件出错了!!!
<serlvet-mapping>中的servlet拼错了居然没发现
l和v调转了
菜继续 2011-05-23
  • 打赏
  • 举报
回复
public class HelloWorldServlet implements HttpServlet

cscxxx 2011-05-23
  • 打赏
  • 举报
回复
lz要不先用这简单的servlet试


public class HelloWorld extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
PrintWriter out = resp.getWriter();
out.println("<html>");
out.println("<head>");
out.println("<title>Servlet</title>");
out.println("</head>");
out.println("<body>");
out.println("<h1> HelloWorld!</h1>");
out.println("</body>");
out.println("</html>");
out.close();
}
}
bulver 2011-05-23
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 sunlotus0 的回复:]

引用 4 楼 bulver 的回复:

引用 3 楼 sunlotus0 的回复:

public class HelloWorldServlet implements Servlet
改成
public class HelloWorldServlet implements HttpServlet

应该就可以了

我改成下面这样了,试了还是不行
Java code

……
[/Quote]
是啊,真难弄,继续求解答
bulver 2011-05-23
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 tarkhnas 的回复:]

你配置文件出错了!!!
<serlvet-mapping>中的servlet拼错了居然没发现
l和v调转了
[/Quote]
真的是哈,虽然我猜到可能是什么小地方写错了,但是就是看不出来,还是群众的眼睛亮,谢了谢了~ 改了试了下,没问题了~
悠忧虫 2011-05-22
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 bulver 的回复:]

引用 3 楼 sunlotus0 的回复:

public class HelloWorldServlet implements Servlet
改成
public class HelloWorldServlet implements HttpServlet

应该就可以了

我改成下面这样了,试了还是不行
Java code

import javax.servlet.ht……
[/Quote]

这样不行的话,我也不知道是哪的问题了
你的路径配置的好像没什么问题
bulver 2011-05-22
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 sunlotus0 的回复:]

public class HelloWorldServlet implements Servlet
改成
public class HelloWorldServlet implements HttpServlet

应该就可以了
[/Quote]
我改成下面这样了,试了还是不行

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class HelloWorldServlet extends HttpServlet{
悠忧虫 2011-05-22
  • 打赏
  • 举报
回复
public class HelloWorldServlet implements Servlet
改成
public class HelloWorldServlet implements HttpServlet

应该就可以了
bulver 2011-05-22
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 lianghaijian 的回复:]

检查一下项目路径是不是有问题
[/Quote]

能说得具体点么?哪个项目路径啊?项目名是HelloWorld,路径应该就是这个吧 D:\WorkSpace\Tomcat 6.0\webapps\HelloWorld
危险的大猫 2011-05-22
  • 打赏
  • 举报
回复
检查一下项目路径是不是有问题

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧