Hi All,
I have created a html page having a checkbox and two servlet.When a user select submit the form using the get method it tranfer the req to first servlet.First
servlet redirect the request to the next servlet using response.redirect("url") what i need it is the second servlet has to collect the data selected by the user.The problem is iam unable to find the selected checkbox by the user.O/P iam getting is NullPointerException
The code is:
Html Page :
<html>
<head>this is 3 parmeter
<title>this is first</title></head>
<body>
<form Method =get action = "redi">
color :<select name = "c">
<option> light
<option> dark
<option> thick
<option> amber
</select></br>
<input type = checkbox name =a value = "first">first</br>
<input type =checkbox name =a value ="second">second</br>
<input type =checkbox name =a value = "third">third</br>
<input type = "submit">
</form></body>
</html>
First Servlet code is
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class redi extends HttpServlet
{
public void doGet(HttpServletRequest req ,HttpServletResponse res)throws IOException,ServletException
{
res.setContentType("text/html");
PrintWriter pw=res.getWriter();
res.sendRedirect("fin");
}
}
Second servlet code is:
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class fin extends HttpServlet
{
public void doGet(HttpServletRequest req,HttpServletResponse res)throws IOException,ServletException
{
res.setContentType("text/html");
PrintWriter pw=res.getWriter();
pw.println("from final");
String s3=req.getParameter("c");
pw.println("</br>");
String ss[]=req.getParameterValues("a");
//String ss1=req.getParameterValues("a")[1];
//pw.println(ss1+" values at 1 </br>"+"vlues : ");
for(String st:ss)
pw.println(st+" , ");
pw.println(s3+"<br>");
pw.println("sdaf"+"<br>");
pw.println(req.getHeader("User-Agent")+"<br>");
pw.println(req.getMethod()+"<br>");
pw.println(req.getContentLength()+": header names");
}
}
Thanks in Advance
sankar