关于servlet的一个问题

hardsonxu 2005-04-04 09:07:51
package servlets;

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;

public class Registration extends HttpServlet
{
public void doPost(HttpServletRequest req,HttpServletResponse res)
throws ServletException,IOException
{

res.setContentType("text/html");
PrintWriter out=res.getWriter();
out.println("<html><body>hhhhhh</body></html>");
}
}

tomcat5.0 web.xml配置:

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"
"http://java.sun.com/dtd/web-app_2_2.dtd">

<web-app>
<servlet>
<servlet-name>NewRegistration</servlet-name>
<servlet-class>servlets.Registration</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>NewRegistration</servlet-name>
<url-pattern>/NewRegistration</url-pattern>
</servlet-mapping>
</web-app>

在IE打入
http://localhost:8080/ChatRoom_ServerVersion/NewRegistration

出错:
type Status report
message HTTP method GET is not supported by this URL
description The specified HTTP method is not allowed for the requested resource (HTTP method GET is not supported by this URL).

如果把doPost改成doGet就运行正常,请教是怎么回事?
...全文
86 点赞 收藏 2
写回复
2 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
nationally 2005-04-04
二楼正解!
up!
回复
taglib 2005-04-04
加一个处理GET的方法

public class Registration extends HttpServlet
{
public void doGet(HttpServletRequest req,HttpServletResponse res)
throws ServletException,IOException
{
doPost(req,res);
}

public void doPost(HttpServletRequest req,HttpServletResponse res)
throws ServletException,IOException
{

res.setContentType("text/html");
PrintWriter out=res.getWriter();
out.println("<html><body>hhhhhh</body></html>");
}
}

回复
发帖
Java EE
创建于2007-09-28

6.6w+

社区成员

J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
申请成为版主
帖子事件
创建了帖子
2005-04-04 09:07
社区公告
暂无公告