关于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就运行正常,请教是怎么回事?
...全文
129 2 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
leekooqi 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>");
}
}

67,549

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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