Tomcat怪问题!

lanseliuying 2007-01-10 05:58:15
我用Tomcat,运行Servlet时,只要用doPost()方法就报错。
HTTP Status 405 - HTTP method GET is not supported by this URL

而用doGet()则正常,为什么?
...全文
187 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
foamflower 2007-10-27
  • 打赏
  • 举报
回复
好像两个都要重写吧。
lanseliuying 2007-01-10
  • 打赏
  • 举报
回复
我在页面中是用post 提交的啊
gzloveqxin 2007-01-10
  • 打赏
  • 举报
回复
在servlet中你們只寫了doPost()方法,而沒有寫doGet()方法對吧?

這個時候,如果你們在表單中提交數據的時候,如果是get方法提交,那麼就找不到你們

所要轉向的jsp或者html頁面,也就是報上述錯誤:

HTTP Status 405 - HTTP method GET is not supported by this URL

多寫點就知道這些類似於404,405,500...的錯誤了。建議初學時最好還是用一些tomcat為好,這

樣也方便將來用快速開發工具的時候更快速!!!

simaping 2007-01-10
  • 打赏
  • 举报
回复
我的也是这个问题,为什么?我的代码如下:
public class Sayhi1 extends HttpServlet
{
public void init(ServletConfig config)throws ServletException
{
super.init(config);
}
public void doPost(HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException
{
response.setContentType("Text/html;charset=GB2312");
PrintWriter out=response.getWriter();
request.setCharacterEncoding("GB2312");

out.println("<html><head><title>Say hi</title><head><body>");

out.println("welcome!");
out.println("</body></html>");
out.close();
}

public void destroy(){}
}
fool_leave 2007-01-10
  • 打赏
  • 举报
回复
你的doPost方法体是什么?doGet呢?
这个错误看上去应该是你没有写doGet方法,而请求是通过GET方式发起的而不是POST
lanseliuying 2007-01-10
  • 打赏
  • 举报
回复
原来一直用IDE没有单独用过Tomcat,没注意过这个问题,请高手解答!

62,614

社区成员

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

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