I am learning Java Servlets. Trying to implement the doPost() method, however I get an error that "HTTP Status 405 - HTTP method POST is not supported by this URL".
Code
<html>
<body>
<center>
<form name="Form1" action="http://localhost:8080/examples/servlet/ColorGetServlet" method="post">
<B>Color:</B>
<select name="color" size="1">
<option value="Red">Red</option>
<option value="Green">Green</option>
<option value="Blue">Blue</option>
</select>
<br><br>
<input type=submit value="Submit">
</form>
</body>
</html>
Servlet
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class ColorGetServlet extends HttpServlet{
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException{
String color = request.getParameter("color");
response.setContentType("text/html");
PrintWriter pw = response.getWriter();
pw.println("<B>The Selected Color is: ");
pw.println(color);
pw.close();
}
}
Will appreciate if anyone can tell me what am I doing wrong.