getParameterValues() method of Servlet Request
Example on getParameterValues() method of Servlet Request
index.html
<font
face="verdana" size="2px">
<form action="onGPV"
method="post">
Habits :
<input
type="checkbox" name="habits"
value="Reading">Reading
<input
type="checkbox" name="habits"
value="Movies">Movies
<input
type="checkbox" name="habits"
value="Writing">Writing
<input
type="checkbox" name="habits"
value="Singing">Singing
<input
type="submit" value="Submit">
</form>
</font>
OngetParameterNames.java
package java4s;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class OngetParameterValues extends HttpServlet
{
protected void doPost(HttpServletRequest
req,HttpServletResponse res)throws ServletException,IOException
{
PrintWriter pw=res.getWriter();
res.setContentType("text/html");
String[] values=req.getParameterValues("habits");
pw.println("Selected
Values...");
for(int
i=0;i<values.length;i++)
{
pw.println("<li>"+values[i]+"</li>");
}
pw.close();
}
}
web.xml
<web-app>
<servlet>
<servlet-name>ongetParameterValues</servlet-name>
<servlet-class>java4s.OngetParameterValues</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ongetParameterValues</servlet-name>
<url-pattern>/onGPV</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
</web-app>
Comments
Post a Comment