首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

Http404异常!求解决方法~各位帮帮忙哈

2012-04-07 
Http404错误!急求解决办法~各位帮帮忙哈`我建立的目录如下D:\Tomcat\apache-tomcat-6.0.35\webapps\0202

Http404错误!急求解决办法~各位帮帮忙哈`
我建立的目录如下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





请各位帮帮忙啊~~~万分感谢!!!

[解决办法]
DoGet方法应该写成doGet,你写成大写了。
[解决办法]
写servlet的时候最好放在包内,写它的完整路径:包名+类名
[解决办法]
环境变量CATALINA_HOME设了没?你的配置没问题,就那个DoGet错了。
应该是你的tomcat问题
[解决办法]
HelloServlet
serlvet必须要有包名 请加上包名

热点排行