Tomcat怪问题! 我用Tomcat,运行Servlet时,只要用doPost()方法就报错。HTTP Status 405 - HTTP method GET is not supported by this URL而用doGet()则正常,为什么? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 原来一直用IDE没有单独用过Tomcat,没注意过这个问题,请高手解答! 你的doPost方法体是什么?doGet呢?这个错误看上去应该是你没有写doGet方法,而请求是通过GET方式发起的而不是POST 我的也是这个问题,为什么?我的代码如下: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(){}} 在servlet中你們只寫了doPost()方法,而沒有寫doGet()方法對吧?這個時候,如果你們在表單中提交數據的時候,如果是get方法提交,那麼就找不到你們所要轉向的jsp或者html頁面,也就是報上述錯誤:HTTP Status 405 - HTTP method GET is not supported by this URL多寫點就知道這些類似於404,405,500...的錯誤了。建議初學時最好還是用一些tomcat為好,這樣也方便將來用快速開發工具的時候更快速!!! 我在页面中是用post 提交的啊 常量与变量 求助,一个闹钟的测试程序,加入的音频文件路径该如何写 多线程的static 读取不到cookie中值的问题 关于HashMap 在linux下调系统命令CD出现的问题,求助! 谁能帮我看看这是什么问题 JList中如何实现显示两列数据? StringBuffer使用最后用不用清? 上海的朋友进来看看!!(400分) 请教使用JCREATOR时遇到的问题.请帮助. java中 main()方法里可以定义static变量或方法吗?
这个错误看上去应该是你没有写doGet方法,而请求是通过GET方式发起的而不是POST
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(){}
}