Reputation:
I made two radio buttons like this:
<input type="radio" name="One" value="Send To All" checked="checked" />
<input type="radio" name="One" value="Send To Recent" />
But when I tried to fetch the value of radio button via following line of code:
request.getParameter("Send To All");
I got a NullPointerException
on the same line. So can anyone tell me the right way to get the value of radio button?
Thanks in advance.
Upvotes: 0
Views: 337
Reputation: 1413
String value= request.getParameter("One");// used to get the value
out.println(value);
it will work
Upvotes: 0
Reputation: 121998
Actually on server side we can access the form values by name
attribute not with the value
attribute
So it should be
request.getParameter("One");
And the line it self won't give null pointer exception and it returns null value if there is no parameter with that name.
And as commented you have to check like
if(request.getParameter("One").equals("Send To All"){
//TO DO
}
Upvotes: 2