| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1698 人关注过本帖
标题:求助:为什么只能调用doget方法而不能用dopost方法??
取消只看楼主 加入收藏
雪落无语
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2006-9-11
收藏
 问题点数:0 回复次数:2 
求助:为什么只能调用doget方法而不能用dopost方法??

用MyEclipse+Apache Tomcat/6.0.2练习一个Servlet程序,只有doget方法有返回值,dopost方法出错
代码如下:
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 HelloServlet extends HttpServlet {

public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

response.setContentType("text/html");
PrintWriter out = response.getWriter();
out
.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
out.println("<HTML>");
out.println(" <HEAD><TITLE>A Servlet</TITLE></HEAD>");
out.println(" <BODY>");
out.print(" This is ");
out.print(this.getClass());
out.println(", using the GET method");
out.println(" </BODY>");
out.println("</HTML>");
out.flush();
out.close();
}

public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

response.setContentType("text/html");
PrintWriter out = response.getWriter();
out
.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
out.println("<HTML>");
out.println(" <HEAD><TITLE>A Servlet</TITLE></HEAD>");
out.println(" <BODY>");
out.print(" This is ");
out.print(this.getClass());
out.println(", using the POST method");
out.println(" </BODY>");
out.println("</HTML>");
out.flush();
out.close();
}

}


浏览器中只有doget输出了,dopost没输出。
如果把上面的代码分成两个,一个doget和一个dopost单独运行,doget可以正常输出,dopost报错了,
dopost报错如下:
HTTP Status 405 - HTTP method GET is not supported by this URL

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

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).


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

Apache Tomcat/6.0.2

不知道怎么回事,请大家指点一下,本人太菜了

搜索更多相关主题的帖子: doget dopost 
2007-08-08 10:37
雪落无语
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2006-9-11
收藏
得分:0 

代码中没有method啊,说具体点好吗?


努力为梦想创造可能!~
2007-08-08 15:45
雪落无语
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2006-9-11
收藏
得分:0 
我试试看,3Q了

努力为梦想创造可能!~
2007-08-09 10:21
快速回复:求助:为什么只能调用doget方法而不能用dopost方法??
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.038316 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved