• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Doubt in reDirect and post

 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 510
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi sundar, is this a doubt or a question?

I do not doubt that the redirect is happenning so I will assume that your question is "Why is the posted parameter lost?"

When you re-direct you return to the browser and the browser sends a new request (which does not have your posted info) to where ever you wanted to re-direct. If you forward, you will not lose your posted information

Please let us know if this was your question and that you have received the information you need to understand what is happening
 
sundar sankar
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Michael Ku,
Thanks a lot you are perfactely rignt and your explaination cleared my doubt.
regards
sankar
 
reply
    Bookmark Topic Watch Topic
  • New Topic