3 Replies Latest reply on Apr 4, 2007 5:42 PM by Wladyslaw Niedowolny

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

    Wladyslaw Niedowolny Newbie

      I am new to Jboss and J2EE and I get HTTP Status 405 when accessing my simple servlet. I've noticed that I get this error only when I try to return HTML and not plain text. When I return plain text response doGet works fine. What do I do to solve this problem???

        • 1. Re: HTTP Status 405 - HTTP method GET is not supported by th
          prakash Newbie

          Hello,

          405 status code will be return when you try to access an Http method(get/post/etc...) which is not available.

          I think, you are having doGet method and you are asking for doPost. If that is the case, then by adding following code in the servlet will solve the problem.

          public void doPost(HttpServletRequest req, HttpServletResponse res)
           throws IOException, ServletException {
           doGet(req, res);
          }
          


          • 2. Re: HTTP Status 405 - HTTP method GET is not supported by th
            Wladyslaw Niedowolny Newbie

            Keep in mind that when I return PLAIN TEXT:

            public void doGet(HttpServletRequest request,
             HttpServletResponse response)
             throws ServletException, IOException{
             PrintWriter out = response.getWriter();
             out.println("Hellow World");
             }

            There is no problem. I get this error only when I return HMTL:
            public void doGet(HttpServletRequest request,
             HttpServletResponse response)
             throws ServletException, IOException{
             super.doGet(request, response);
             //Tell the browser that you?re sending it HTML
             response.setContentType("text/html");
            
             PrintWriter out = response.getWriter();
            
             String docType =
             "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 "+
             "Transitional//EN\">\n";
            
             out.println(docType +
             "<HTML>\n<HEAD>\n<TITLE>HELLO</TITLE>\n</BODY>\n</HTML>");
             }


            Could that be some server settings??? I'm running JBoss 4.0

            • 3. Re: HTTP Status 405 - HTTP method GET is not supported by th
              Wladyslaw Niedowolny Newbie

              I have solved the problem. There was a couple errors:

              1) When creating HTTPServlet in Eclipse I checked "include doGet()" which automatically included statement to

              super.get(req, res);


              2) Another error that I had was very trivial. My HTML syntax was not valid.
              http://validator.w3.org/ is a great webpage to validate HTML syntax.