![]() |
HTTP Status 405 - HTTP method POST is not supported by this URL
I am using Apache Tomcat
I got the following error when invoking a jsp. 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). My 2 files are LoginServlet1 import javax.servlet.*; import javax.servlet.http.*; import java.io.*; import java.util.*; public class LoginServlet1 extends HttpServlet { private void sendLoginForm(HttpServletResponse response, boolean withErrorMessage) throws ServletException, IOException { response.setContentType("text/html"); PrintWriter out = response.getWriter(); out.println("<HTML>"); out.println("<HEAD>"); out.println("<TITLE>Login</TITLE>"); out.println("</HEAD>"); out.println("<BODY>"); if (withErrorMessage) out.println("Login failed. Please try again.<BR>"); out.println("<BR>"); out.println("<BR>Please enter your user name and password."); out.println("<BR><FORM METHOD=POST>"); out.println("<BR>User Name: <INPUT TYPE=TEXT NAME=userName>"); out.println("<BR>Password: <INPUT TYPE=PASSWORD NAME=password>"); out.println("<BR><INPUT TYPE=SUBMIT VALUE=Submit>"); out.println("</FORM>"); out.println("</BODY>"); out.println("</HTML>"); } public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { sendLoginForm(response, false); } public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String userName = request.getParameter("userName"); String password = request.getParameter("password"); if (userName!=null && password!=null && userName.equals("hemanth") && password.equals("balaji")) { RequestDispatcher rd = request.getRequestDispatcher("WelcomeServlet"); rd.forward(request, response); } else { sendLoginForm(response, true); } } } and, WelcomeServlet.java import javax.servlet.*; import javax.servlet.http.*; import java.io.*; import java.util.*; public class WelcomeServlet extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { PrintWriter out = response.getWriter(); out.println("<HTML>"); out.println("<HEAD>"); out.println("<TITLE>Hi from Servlet Demo</TITLE>"); out.println("</HEAD>"); out.println("<BODY>"); out.println("Welcome to the Servlet Demo"); out.println("</BODY>"); out.println("</HTML>"); } } Thanks and regards, Hemanth http://www.freejavaguide.com |
:
LoginServlet1Alot easier to read your code if you use the code bars. :) |
Hi i see no change in the code.
|
I never said nor implied that their was a change in the code but it is ALOT easier to read and understand their for getting a better reply.
|
Quote:
|
Maybe it is the "WelcomeServlet" page that can't handle POSTs. Maybe you could try doing something simple when you get the original POST, say just returning back some simple html.
|
| All times are GMT -5. The time now is 5:10 AM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC