When I want to send a radio value from a form on a HTML page to a Java Servlet, this always seems to be a null value, instead of "1" or "2" or...
Here is the HTML code I have:
<form method="post" action="/testWeb/animalsurvey" target="_blank">
<p>What is your favorite pet?</p>
<p><input type="radio" name="animal" value="1" />Dog<br />
<input type="radio" name="animal" value="2" />Cat<br />
<input type="radio" name="animal" value="3" />Bird<br />
<input type="radio" name="animal" value="4" />Snake<br />
<input type="radio" name="animal" value="5" checked="checked" />None</p>
<p><input type="submit" value="Submit" /></p>
This is the Java Servlet code:
protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
PrintWriter out = response.getWriter();
String value = request.getParameter("name");
out.println(value);
}
Web.xml code, which show the servlet mapping:
<servlet>
<servlet-name>animalsurvey</servlet-name>
<description>A survey servlet.</description>
<servlet-class>be.SurveyServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>animalsurvey</servlet-name>
<url-pattern>/animalsurvey</url-pattern>
</servlet-mapping>
I don't know if I'm blind to see it here, but what am I doing wrong?
答案 0 :(得分:1)
Looks like it is the parameter name:
Please try:
String value = request.getParameter("animal");