Servlet错误

x_chao 2009-06-07 04:24:42
servlet文件

package zhangchao.com;

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 Hello extends HttpServlet {

/**
* Constructor of the object.
*/
public Hello() {
super();
}

/**
* Destruction of the servlet. <br>
*/
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
}

/**
* The doGet method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to get.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost(request,response);

}

/**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to post.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException
{
response.setContentType("text/html;charset=gb2312");
String name=request.getParameter("username");
String password=request.getParameter("password");
PrintWriter out=response.getWriter();
out.println("<html>");
out.println("<body>");
out.println(name);
out.println(password);
out.println("</body>");
out.println("</html>");

}

public void init() throws ServletException {
// Put your code here
}

}


web.xml 文件


<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4"
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">
<servlet>
<servlet-name>Hello</servlet-name>
<servlet-class>zhangchao.com.Hello</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>Hello</servlet-name>
<url-pattern>/servlet/Hello</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>




jsp 文件

<%@ page language="java" import="java.util.*" pageEncoding="GB2312"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>

<body>
<form action="/servlet/Hello">
<table>
<tr><td colspan="2" align="center">userlogin</td></tr>
<tr><td>userName:</td><td><input type="text" name="username" size="10"></td></tr>
<tr><td>Password:</td><td><input type="password" name="password" size="10"></td></tr>
<tr><td><input type="submit" value="submit"></td><input type="reset" value="reset"></tr>
</table>




</form>
</body>
</html>



错误页面


HTTP Status 404 - /web/servlet/Hello

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

type Status report

message /web/servlet/Hello

description The requested resource (/web/servlet/Hello) is not available.


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

Apache Tomcat/6.0.20





总是这个错误,在线等。谢谢了
...全文
21 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
yangkangoo12 2009-06-07
  • 打赏
  • 举报
回复
你的工程名是叫web吗 如果是的话路径就没错误 可能是工程没有在tomcat上发布
yanghn_2008 2009-06-07
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 qiheia 的回复:]
<form action="/servlet/Hello">
改成这样
<form action="servlet/Hello">
试试
[/Quote]

我又找到你了,麻烦你去看一下我的帖子。。。
qiheia 2009-06-07
  • 打赏
  • 举报
回复
<form action="/servlet/Hello">
改成这样
<form action="servlet/Hello">
试试

81,092

社区成员

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

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