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

Hi,

It might be related to the security settings on your web server and not to the code. What is your web server, and TomCat support if you use any.

Loren Soth

your welcomeServlet doesn't support POST requests...
neither does calling one JSP from another.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.