Http404错误!急求解决办法~各位帮帮忙哈`

Y0328 2012-03-14 03:56:24
我建立的目录如下D:\Tomcat\apache-tomcat-6.0.35\webapps\02;02文件夹中有:welcome.html和WEB-INF文件夹;WEB-INF中有web.xml和classes;classes中有WelcomeServlet.java和WelcomeServlet.class


welcome.html内容 :
<html>
<head>
<title>欢迎您!</title>
</head>
<body>
<form action="welcome" method="get">
请输入用户名:<input type="text" name="username"><br>
<input type="submit" value="提交">
</form>
</body>
</html>


WelcomeServlet.java内容:
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 WelcomeServlet extends HttpServlet
{
private String greeting;
public void init()
{greeting=getInitParameter("greeting");}
public void DoGet(HttpServletRequest req,HttpServletResponse resp) throws ServletException,IOException
{
req.setCharacterEncoding("gb2312");
String username=req.getParameter("username");
String welcomeInfo=greeting+", "+username;
resp.setContentType("text/html");
PrintWriter out=resp.getWriter();
out.println("<html><head><title>");
out.println("Welcome Page");
out.println("</head></title>");
out.println("<body>");
out.println(welcomeInfo);
out.println("</body></html>");
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/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">


<servlet>
<servlet-name>HelloServlet</servlet-name>
<servlet-class>HelloServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>HelloServlet</servlet-name>
<url-pattern>/helloservlet</url-pattern>
</servlet-mapping>


<servlet>
<servlet-name>WelcomeServlet</servlet-name>
<servlet-class>WelcomeServlet</servlet-class>
<init-param>
<param-name>greeting</param-name>
<param-value>Welcome you</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>WelcomeServlet</servlet-name>
<url-pattern>/welcome</url-pattern>
</servlet-mapping>

</web-app>


WelcomeServlet.java编译通过,在浏览器地址中输入:http://localhost:8080/02/welcome.html,显示出网页并输入相关数据后,点击“提交”按钮却出现一个错误页,错误页如下:

HTTP Status 404 - Servlet WelcomeServlet is not available

--------------------------------------------------------------------------------

type Status report

message Servlet WelcomeServlet is not available

description The requested resource (Servlet WelcomeServlet is not available) is not available.


--------------------------------------------------------------------------------

Apache Tomcat/6.0.35





请各位帮帮忙啊~~~万分感谢!!!
...全文
542 20 打赏 收藏 转发到动态 举报
写回复
用AI写文章
20 条回复
切换为时间正序
请发表友善的回复…
发表回复
Y0328 2012-03-14
  • 打赏
  • 举报
回复
已经解决 文件夹Classes改成classes就好了
Y0328 2012-03-14
  • 打赏
  • 举报
回复
已经被我同学解决了。。。居然是因为文件夹Classes写错了 应该把C小写 即文件夹名应该为classes
Y0328 2012-03-14
  • 打赏
  • 举报
回复
加上了包 可是还是不对。。。
ylovep 2012-03-14
  • 打赏
  • 举报
回复
HelloServlet
serlvet必须要有包名 请加上包名
Y0328 2012-03-14
  • 打赏
  • 举报
回复
我同学装得Tomcat是好的 可是我这整个工程拷她那儿也出现了一样的错误。。。
噢噢噢噢 2012-03-14
  • 打赏
  • 举报
回复
重启tomcat 还出错的话就重新下载一个
Y0328 2012-03-14
  • 打赏
  • 举报
回复
环境变量CATALINA_HOME 设好了 可是还是不对 刚跳出的是500错误,刷新后又变成404错误了
噢噢噢噢 2012-03-14
  • 打赏
  • 举报
回复
tomcat的路径 比如C:\tomcat-7
Y0328 2012-03-14
  • 打赏
  • 举报
回复
环境变量CATALINA_HOME 好像是没有 请问十楼那环境变量CATALINA_HOME 的变量值应该怎么填? 谢谢
Y0328 2012-03-14
  • 打赏
  • 举报
回复
环境变量CATALINA_HOME 好像是没有 请问十楼那环境变量CATALINA_HOME 的变量值应该怎么填? 谢谢
噢噢噢噢 2012-03-14
  • 打赏
  • 举报
回复
环境变量CATALINA_HOME设了没?你的配置没问题,就那个DoGet错了。
应该是你的tomcat问题
Y0328 2012-03-14
  • 打赏
  • 举报
回复
已经放到包里,可还是不对 现在执行的时候会先跳出500错误 然后又出现404错误
Y0328 2012-03-14
  • 打赏
  • 举报
回复
那会不会是我之前的tomcat没装好啊??http://localhost:8080/是对的
我是先装了JDK,然后官网上下了Tomcat6.0 解压后就直接用了 完全菜鸟啊。。求帮助~
充电中 2012-03-14
  • 打赏
  • 举报
回复
没有问题啊
Y0328 2012-03-14
  • 打赏
  • 举报
回复
已经改成doGet了 可是还是不对。。。
sd722522 2012-03-14
  • 打赏
  • 举报
回复
1楼正解
噢噢噢噢 2012-03-14
  • 打赏
  • 举报
回复
没问题!
star95hmz 2012-03-14
  • 打赏
  • 举报
回复
写servlet的时候最好放在包内,写它的完整路径:包名+类名
dryZeng 2012-03-14
  • 打赏
  • 举报
回复
DoGet方法应该写成doGet,你写成大写了。

81,092

社区成员

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

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