Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 10-13-2008, 12:19 AM
Member
 
Join Date: Jun 2008
Location: Australia
Posts: 42
Rep Power: 0
javanewbie is on a distinguished road
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

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

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
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>
		/login
	</url-pattern>
    </servlet-mapping>
   <servlet-mapping>
        <servlet-name>
		WelcomeLotto
	</servlet-name>
        <url-pattern>
		/welcome
	</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:

Quote:
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.
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 10-13-2008, 02:08 AM
Norm's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Heredia, Costa Rica
Posts: 2,225
Rep Power: 4
Norm is on a distinguished road
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 02:33 AM.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 10-13-2008, 03:49 AM
Member
 
Join Date: Jun 2008
Location: Australia
Posts: 42
Rep Power: 0
javanewbie is on a distinguished road
Default
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:

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:

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:

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.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 10-13-2008, 02:01 PM
Norm's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Heredia, Costa Rica
Posts: 2,225
Rep Power: 4
Norm is on a distinguished road
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.
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 12-24-2008, 09:38 AM
Member
 
Join Date: Dec 2008
Location: US
Posts: 1
Rep Power: 0
cwxwwwxwwxwx is on a distinguished road
Send a message via ICQ to cwxwwwxwwxwx
Default hello guys need advice
well, hi admin adn people nice forum indeed. how's life? hope it's introduce branch
__________________
always online
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


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


All times are GMT +2. The time now is 10:07 PM.



VBulletin, Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org