Results 1 to 8 of 8
- 10-13-2008, 12:19 AM #1
Member
- Join Date
- Jun 2008
- Location
- Australia
- Posts
- 43
- Rep Power
- 0
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
WelcomeLotto.javaJava 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
web.xmlJava 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
here's some part
everytime i access http: //localhost:8080/workspace/login , it works pretty fine. but once i click the submit button, a message appears like this: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>
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?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
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.
- 10-13-2008, 02:08 AM #2
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 URLLast edited by Norm; 10-13-2008 at 02:33 AM.
- 10-13-2008, 03:49 AM #3
Member
- Join Date
- Jun 2008
- Location
- Australia
- Posts
- 43
- Rep Power
- 0
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(" "); 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:
web.xml: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>"); } } }
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.
- 10-13-2008, 02:01 PM #4
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.
- 12-24-2008, 09:38 AM #5
Member
- Join Date
- Dec 2008
- Location
- US
- Posts
- 1
- Rep Power
- 0
hello guys need advice
well, hi admin adn people nice forum indeed. how's life? hope it's introduce branch ;)
- 09-13-2009, 03:16 AM #6
Member
- Join Date
- Sep 2009
- Posts
- 1
- Rep Power
- 0
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
- 09-27-2009, 03:47 AM #7
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); }
- 11-11-2009, 08:29 PM #8
Member
- Join Date
- Nov 2009
- Location
- Boston
- Posts
- 1
- Rep Power
- 0
Similar Threads
-
Imports broken in JSP; HTTP Status 500-
By Aerinai in forum JavaServer Pages (JSP) and JSTLReplies: 0Last Post: 06-13-2008, 10:27 PM -
Http change to HTTP\SSL
By ballyv24 in forum Advanced JavaReplies: 0Last Post: 05-14-2008, 11:32 AM -
HTTP Status 404 - Servlet action is not available---Error
By sireesha in forum Web FrameworksReplies: 0Last Post: 04-18-2008, 07:25 PM -
HTTP Status 404 - Servlet action is not available
By onceuponatime in forum Java ServletReplies: 1Last Post: 12-11-2007, 04:29 PM -
use ftp instead of http
By gabriel in forum Java ServletReplies: 1Last Post: 08-06-2007, 06:06 PM


2Likes
LinkBack URL
About LinkBacks


Bookmarks