I have servlet with doPost method :
package web;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class BeerSelect extends HttpServlet {
public void doPost(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("Beer Selection Advice<br>");
String c = request.getParameter("color");
out.println("<br>Got beer color " + c);
}
}
And I use this form.html:
<html><body>
<h1 align="center">Beer Selection Page</h1>
<form action="SelectBeer.do" method="POST">
<table>
<tr>
<td>Select beer characteristics
Color:
<select name="color" size="1">
<option value="light"> light </option>
<option value="amber"> amber </option>
<option value="brown"> brown </option>
<option value="dark"> dark </option>
</select>
<br><br>
<center>
<input type="SUBMIT">
</center>
</td>
</tr>
</table>
</form>
</body></html>
With my web.xml all things are fine. A have mapped servlet fine. But when I run it, in browser is this error - HTTP method GET is not supported by this URL
I repaces POST method with GET , then i haven't got any errors but the servlet isn't work correct! Do I always need doGet in servlet? And how to use it hear, if I don't need it? I am new at programming, so this is just example what I try to figure out. I will be thanks full if somebody can explain me this.
web.xml:
<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/web-app_2_4.xsd"
version="2.4">
<servlet>
<servlet-name>Ch3 Beer</servlet-name>
<servlet-class>web.BeerSelect</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Ch3 Beer</servlet-name>
<url-pattern>/SelectBeer.do</url-pattern>
</servlet-mapping>
</web-app>