日期:2014-05-18  浏览次数:20602 次

一个简单的Servlet的问题(出错了)
错误代码:
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).

我的Servlet代码:
Java code

package slet;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class HelloWord extends HttpServlet{
    public void init(ServletConfig config) throws ServletException{
        super.init(config);
    }
    public void doGet(HttpServletResponse response,HttpServletRequest request)
        throws IOException,ServletException{
        response.setContentType("text/html;charset=gb2312");
        PrintWriter out=response.getWriter();
        out.println("<html>");
        out.println("<head>");
        out.println("<title>Servlet</title>");
        out.println("</head>");
        out.println("<script>alert('Hello World')</script>");
        out.println("<body></body>");
        out.println("</html>");
    }
    public void doPost(HttpServletResponse response,HttpServletRequest request)
        throws IOException,ServletException{
        response.setContentType("text/html;charset=gb2312");
        PrintWriter out=response.getWriter();
        out.println("<html>");
        out.println("<head>");
        out.println("<title>Servlet</title>");
        out.println("</head>");
        out.println("<script>alert('Hello World')</script>");
        out.println("<body></body>");
        out.println("</html>");
    }
}



谁能解释下这是为何?该怎么处理。。。
谢谢了!



------解决方案--------------------
在doPost()中加入doGet(request,response);删除其他代码
或者在doGet()中加入doPost(request,response);删除其他代码