【0】README
1)本文旨在解决 405: HTTP method GET is not supported by this URL 的问题;
2)本文raw idea is checkouted from http://stackoverflow.com/questions/5370633/405-http-method-get-is-not-supported-by-this-url
【1】解决方法:一句话说完,要重写父类的 doGet 和 doPost方法,就不要调用 super.doGet() 和 super.doPost()方法;如下:
public class SampleServlet extends HttpServlet {private static final long serialVersionUID = -5404916983906926869L;/* @Overridepublic void init() throws ServletException {super.init();}*/@Overrideprotected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {// super.doGet(request, response); // should be commented outresponse.setContentType("text/plain");PrintWriter out = response.getWriter();System.out.println("console info: 请求SampleServlet GET Method");out.println("GET Method: these info are transmitted into client.");out.flush();}@Overrideprotected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {// super.doPost(request, response); // should be commented outresponse.setContentType("text/plain");PrintWriter out = response.getWriter();System.out.println("请求SampleServlet GET Method");out.print("请求SampleServlet POST Method");out.flush();}/*@Overridepublic void destroy() {super.destroy();}*/
}