![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Programmer
|
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 |
|
|
|
|
|
#2 |
|
Hobbyist Programmer
|
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>");
}
}Alot easier to read your code if you use the code bars. ![]()
__________________
When will Jesus bring the porkchops? |
|
|
|
|
|
#3 |
|
Programmer
|
Hi i see no change in the code.
|
|
|
|
|
|
#4 |
|
Hobbyist Programmer
|
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.
__________________
When will Jesus bring the porkchops? |
|
|
|
|
|
#5 | |
|
Expert Programmer
Join Date: Jun 2005
Posts: 852
Rep Power: 4
![]() |
Quote:
|
|
|
|
|
|
|
#6 |
|
Expert Programmer
Join Date: Jun 2005
Posts: 852
Rep Power: 4
![]() |
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.
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|