Results 1 to 8 of 8
Like Tree2Likes
  • 1 Post By travishein
  • 1 Post By Karthick_sm

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

  1. #1
    javanewbie is offline Member
    Join Date
    Jun 2008
    Location
    Australia
    Posts
    43
    Rep Power
    0

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

    Well. I've been finding a solution how should I fix this stuff.

    I look through the internet and i can't find any.

    I searched the forum and found out that quite a few people have the same problem, but did not find a solution.


    LoginLotto.java

    Java Code:
    package login;
    
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.io.*;
    
    
    public class LoginLotto extends HttpServlet{
    	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
    	{
    		response.setContentType("text/html");
    		PrintWriter out = response.getWriter();
    		
    		out.println("<html>");
    		out.println("  <head>");
                    // and list go down
    WelcomeLotto.java

    Java Code:
    package welcome;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.io.*;
    
    
    public class WelcomeLotto extends HttpServlet{
    	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
    	{
    		response.setContentType("text/html");
    		PrintWriter out = response.getWriter();
    		
    		String strUsername = request.getParameter("username");
    		String strPassword = request.getParameter("password");
    		
    		String strUsername2 = "admin";
    		String strPassword2 = "technology";
    		
    		String strValidateUN = strUsername2;
    		String strValidatePW = strPassword2;
    		
    		if(strUsername != strValidateUN ||strPassword != strValidatePW )
    		{
    			out.println("<html>");
    			out.println("  <head>");
                            // and the list go down
    web.xml

    here's some part
    Java Code:
        <!-- Define servlets that are included in the example application -->
    
    
        <servlet>
            <servlet-name>
               LoginLotto
            </servlet-name>
            <servlet-class>
                login.LoginLotto
            </servlet-class>
        </servlet>
    	    <servlet>
            <servlet-name>
               WelcomeLotto
            </servlet-name>
            <servlet-class>
                welcome.WelcomeLotto
            </servlet-class>
        </servlet>
        
        <!-- JSPC servlet mappings start -->
    
        <servlet-mapping>
            <servlet-name>
    		LoginLotto
    	</servlet-name>
            <url-pattern>
    		[B]/login[/B]
    	</url-pattern>
        </servlet-mapping>
       <servlet-mapping>
            <servlet-name>
    		WelcomeLotto
    	</servlet-name>
            <url-pattern>
    		[B]/welcome[/B]
    	</url-pattern>
        </servlet-mapping>
    </web-app>
    everytime i access http: //localhost:8080/workspace/login , it works pretty fine. but once i click the submit button, a message appears like this:

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

    type Status report

    message HTTP method POST is not supported by this URL

    description The specified HTTP method is not allowed for the requested resource (HTTP method POST is not supported by this URL).
    Apache Tomcat/5.0.28
    as i look at my address bar, it was posted as http ://localhost:8080/workspace/welcome - that only shows that the process moved on the next servlet. but why im getting the http status 405?

    soon, as i click the address bar, then pressing enter (without editing the address path), the Welcome part was fixed.


    how should i get rid of http status 405?

    // dont mind the links, i did it intentionally, i cant post any links yet.

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,792
    Rep Power
    25

    Default

    Can you show the HTML that causes the error code?

    Your question asks about GET but the error message has POST?
    HTTP Status 405 - HTTP method POST is not supported by this URL
    Last edited by Norm; 10-13-2008 at 03:33 AM.

  3. #3
    javanewbie is offline Member
    Join Date
    Jun 2008
    Location
    Australia
    Posts
    43
    Rep Power
    0

    Default

    Quote Originally Posted by Norm View Post
    Can you show the HTML that causes the error code?

    Your question asks about GET but the error message has POST?
    HTTP Status 405 - HTTP method POST is not supported by this URL
    I'm confused with your question posted.

    Here's the exact codes I put inside the .java file.

    LoginLotto.java:

    Java Code:
    package login;
    
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.io.*;
    
    
    public class LoginLotto extends HttpServlet{
    	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
    	{
    		response.setContentType("text/html");
    		PrintWriter out = response.getWriter();
    		
    		out.println("<html>");
    		out.println("  <head>");
    		out.println("    <title> EZ LOTTO: Login</title>");
    		    
    		out.println("    <style type='text/css'>");
    		out.println("       body { background: url('image1.gif') }");
    		out.println("    </style>");
    
    		out.println("    <script language='JavaScript'>");
    
    		out.println("    function verify() {");
    		out.println("      var themessage = 'Invalid input. Username/Password is required.';");
    		out.println("        if (document.form.first.value=='' || document.form.last.value=='') {");
    		out.println("          themessage = themessage + ' - EZ Lotto';");
    		out.println("        }");
    		    
    		out.println("        if (themessage == 'Invalid input. Username/Password is required.') {");
    		out.println("          document.form.submit();");
    		out.println("        }");
    		out.println("        else {");
    		out.println("          alert(themessage);");
    		out.println("          return false;");
    		out.println("        }");
    		out.println("    }");
    		out.println("    </script>");
    
    		out.println("  </head>");
    
    		out.println("  <body>");
    
    		out.println("  <form name=\"form\" action =\"welcome\" method=\"POST\">");
    		out.println("    <br><br><br><br><br>");
    		out.println("    <font face='verdana,arial' size=-1>");
    		out.println("    <center>");
    		out.println("      <table cellpadding=4 cellspacing=0 border=0>");
    		out.println("        <tr><td bgcolor='black'>");
    		out.println("      <table cellpadding=0 cellspacing=0 border=0 width=100%>");
    		out.println("        <tr><td bgcolor='black' align=center style='padding:2;padding-bottom:4'>");
    		out.println("          <b><font size=-1 color='white'>Enter your username and password</font>");
    		out.println("        </th></tr>");
    		out.println("        <tr><td bgcolor='white' style='padding:5'><br>");
    		out.println("    <center>");
    		out.println("      <table>");
    		out.println("        <tr><td>");
    		out.println("          <font face='verdana,arial' size=-1>Username:");
    		out.println("        </td><td>");
    		out.println("          <input type='text' name='first'>");
    		out.println("        </td></tr>");
    		out.println("        <tr><td>");
    		out.println("          <font face='verdana,arial' size=-1>Password:");
    		out.println("        </td><td>");
    		out.println("          <input type='password' name='last'>");
    		out.println("        </td></tr>");
    		out.println("        <tr><td>");
    		out.println("          <font face='verdana,arial' size=-1>");
    		out.println("          &nbsp;");
    		out.println("        </td><td>");
    		out.println("          <font face='verdana,arial' size=-1>");
    		out.println("          <input type='button' value='Login' name='login' onclick='verify();''>");
    		out.println("          <input type='reset' value='Clear' name='clear'>");
    		out.println("        </td></tr>");
    		out.println("      </table>");
    		out.println("    </center>");
    		out.println("    </form>");
    		out.println("    </td></tr>");
    		out.println("    </table></td>");
    		out.println("  </form>");
    		out.println("  <body>");
    		out.println("</html>");
    	}
    }

    WelcomeLotto.java:

    Java Code:
    package welcome;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.io.*;
    
    
    public class WelcomeLotto extends HttpServlet{
    	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
    	{
    		response.setContentType("text/html");
    		PrintWriter out = response.getWriter();
    		
    		String strUsername = request.getParameter("username");
    		String strPassword = request.getParameter("password");
    		
    		String strUsername2 = "admin";
    		String strPassword2 = "technology";
    		
    		String strValidateUN = strUsername2;
    		String strValidatePW = strPassword2;
    		
    		if(strUsername != strValidateUN ||strPassword != strValidatePW )
    		{
    			out.println("<html>");
    			out.println("  <head>");
    			out.println("    <title>EZ LOTTO: Welcome, " + strUsername + "!</title>");
    			    
    			out.println("    <style type='text/css'>");
    			out.println("       body { background: url('image1.gif') }");
    			out.println("    </style>");
    			    
    			out.println("  </head>");
    			out.println("  <body>");
    			out.println("  <form action =\"login\" method=\"POST\">");
    			out.println("    <br><br><br><br><br>");
    			out.println("    <font face='verdana,arial' size=-1>");
    			out.println("    <center>");
    			out.println("      <table cellpadding=4 cellspacing=0 border=0>");
    			out.println("        <tr><td bgcolor='black'>");
    			out.println("      <table cellpadding=0 cellspacing=0 border=0 width=50%>");
    			out.println("        <tr><td bgcolor='black' align=center style='padding:2;padding-bottom:4'>");
    			out.println("          <b><marquee loop='infinite' behavior='alternate' scrollamount='40'>");
    			out.println("             <font size=6 color='white'>WELCOME TO EZ LOTTO!</font>");
    			out.println("             </marquee>");
    			out.println("        </th></tr>");
    			out.println("        <tr><td bgcolor='white' style='padding:5'><br>");
    			out.println("    <center>");
    			out.println("      <table>");
    			out.println("        <tr><td><br>");
    			out.println("          <font face='verdana,arial' size=-1>");
    			out.println("          <input type='submit' value='Back' name='back'>");
    			out.println("        </td></tr>");
    			out.println("          <font size=-4 color='black'>");
    			out.println("		   <b>EZ LOTTO</b> Site is <blink>UNDER CONSTRUCTION.</blink> Come back some other time.<br><br>");
    			out.println("      </table>");
    			out.println("    </center>");
    			out.println("    </form>");
    			out.println("    </td></tr>");
    			out.println("    </table></td>"); 
    			out.println("  </form>");
    			out.println("  <body>");
    			out.println("</html>");
    		
    		}
    		else
    		{
    			out.println("<html>");
    			out.println("  <head>");
    			out.println("    <title>EZ LOTTO: Invalid Username/Password!</title>");
    			    
    			out.println("    <style type='text/css'>");
    			out.println("       body { background: url('image1.gif') }");
    			out.println("    </style>");
    			    
    			out.println("  </head>");
    			out.println("  <body>");
    			out.println("  <form action =\"login\" method=\"POST\">");
    			out.println("    <br><br><br><br><br>");
    			out.println("    <font face='verdana,arial' size=-1>");
    			out.println("    <center>");
    			out.println("      <table cellpadding=4 cellspacing=0 border=0>");
    			out.println("        <tr><td bgcolor='black'>");
    			out.println("      <table cellpadding=0 cellspacing=0 border=0 width=50%>");
    			out.println("        <tr><td bgcolor='black' align=center style='padding:2;padding-bottom:4'>");
    			out.println("          <b><marquee loop='infinite' behavior='alternate' scrollamount='40'>");
    			out.println("             <font size=6 color='white'>WELCOME TO EZ LOTTO!</font>");
    			out.println("             </marquee>");
    			out.println("        </th></tr>");
    			out.println("        <tr><td bgcolor='white' style='padding:5'><br>");
    			out.println("    <center>");
    			out.println("      <table>");
    			out.println("        <tr><td><br>");
    			out.println("          <font face='verdana,arial' size=-1>");
    			out.println("          <input type='submit' value='Back' name='back'>");
    			out.println("        </td></tr>");
    			out.println("          <font size=-4 color='red'><blink>");
    			out.println("		   You have entered an invalid username/password.<br>");
    			out.println("          Please try again.</blink></font>");
    			out.println("      </table>");
    			out.println("    </center>");
    			out.println("    </form>");
    			out.println("    </td></tr>");
    			out.println("    </table></td>"); 
    			out.println("  </form>");
    			out.println("  <body>");
    			out.println("</html>");
    		}
    	}
    			
    }
    web.xml:

    Java Code:
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <!--
      Copyright 2004 The Apache Software Foundation
    
      Licensed under the Apache License, Version 2.0 (the "License");
      you may not use this file except in compliance with the License.
      You may obtain a copy of the License at
    
          http://www.apache.org/licenses/LICENSE-2.0
    
      Unless required by applicable law or agreed to in writing, software
      distributed under the License is distributed on an "AS IS" BASIS,
      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      See the License for the specific language governing permissions and
      limitations under the License.
    -->
    
    <web-app xmlns="http://java.sun.com/xml/ns/j2ee"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
        version="2.4">
        <!-- Define servlets that are included in the example application -->
    
    
        <servlet>
            <servlet-name>
               LoginLotto
            </servlet-name>
            <servlet-class>
                login.LoginLotto
            </servlet-class>
        </servlet>
    	    <servlet>
            <servlet-name>
               WelcomeLotto
            </servlet-name>
            <servlet-class>
                welcome.WelcomeLotto
            </servlet-class>
        </servlet>
        
        <!-- JSPC servlet mappings start -->
    
        <servlet-mapping>
            <servlet-name>
    		LoginLotto
    	</servlet-name>
            <url-pattern>
    		/login
    	</url-pattern>
        </servlet-mapping>
       <servlet-mapping>
            <servlet-name>
    		WelcomeLotto
    	</servlet-name>
            <url-pattern>
    		/welcome
    	</url-pattern>
        </servlet-mapping>
    </web-app>

    There you have it.

  4. #4
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,792
    Rep Power
    25

    Default

    Can you show the HTML that causes the error code?

    How do you send a request to a server without there being HTML?

    You open a browser, enter a URL, send a request to a server. The server returns a page of HTML containing a <FORM tag. You enter data into the form and press a submit button. The browser sends the request (either a GET or a POST) to the server.
    THe HTML contains an attribute that says to GET or POST.
    The error message you posted says that the HTML used a POST. Your thread title says the HTML used a GET.
    If you will look at the page source in your browser you will be able to see which it is.

  5. #5
    cwxwwwxwwxwx is offline Member
    Join Date
    Dec 2008
    Location
    US
    Posts
    1
    Rep Power
    0

    Default hello guys need advice

    well, hi admin adn people nice forum indeed. how's life? hope it's introduce branch ;)

  6. #6
    margotk is offline Member
    Join Date
    Sep 2009
    Posts
    1
    Rep Power
    0

    Default This worked for me

    Hi,

    I'm posting this for the benefit of others who might encounter this thread after searching for a solution to: 'HTTP Status 405 - HTTP method POST is not supported by this URL'.

    I had the same problem. My initial HTML form (i.e. entry point to the application) is called: form.html.

    I did not have an element for this form within in the <welcome-file-list></welcome-file-list> tags in the web.xml deployment descriptor file.

    Adding this resolved the error:

    <welcome-file>form.html</welcome-file>

    I.e. - in context:

    <welcome-file-list>
    <welcome-file>form.html</welcome-file>
    </welcome-file-list>




    MK

  7. #7
    travishein's Avatar
    travishein is offline Senior Member
    Join Date
    Sep 2009
    Location
    Canada
    Posts
    684
    Rep Power
    6

    Default

    It's likely the form HTML is invoking a POST operation, and your servlet only implements the doGet() method. Since you don't have a doPost(), or in this case, since the POST operation would be the same as the GET anyway, just also implement the doPost() method in your servlets, and have them just call your doGet, like this.

    Java Code:
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
      {
        doGet(request, response);
      }
    sbmk likes this.

  8. #8
    Karthick_sm is offline Member
    Join Date
    Nov 2009
    Location
    Boston
    Posts
    1
    Rep Power
    0

Similar Threads

  1. Imports broken in JSP; HTTP Status 500-
    By Aerinai in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 06-13-2008, 11:27 PM
  2. Http change to HTTP\SSL
    By ballyv24 in forum Advanced Java
    Replies: 0
    Last Post: 05-14-2008, 12:32 PM
  3. HTTP Status 404 - Servlet action is not available---Error
    By sireesha in forum Web Frameworks
    Replies: 0
    Last Post: 04-18-2008, 08:25 PM
  4. HTTP Status 404 - Servlet action is not available
    By onceuponatime in forum Java Servlet
    Replies: 1
    Last Post: 12-11-2007, 05:29 PM
  5. use ftp instead of http
    By gabriel in forum Java Servlet
    Replies: 1
    Last Post: 08-06-2007, 07:06 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •