Following is the code i have written in B.jsp page
Now i want to print the values that are selected in A.jsp page through checkbox in B.jsp page but whenever i m trying to do this as above it gives me an exception in B.jsp page.
Now in B.jsp page i am trying to print a single value but then too it shows me some exception.
So anybody can please point me out that where i am wrong.
Dinesh Remje wrote:@Paul Clapham So what changes shoould i make in my code inorder to make it working.
Also request.getParameter is working but its only printing one value. I need the values that the user select through the checkbox.
What Paul Clapham was asking was the relationship between A.jsp and B.jsp. Other way, how do you invoke B.jsp ? Is it from A.jsp? or you invoke it in the browser directly?
If you invoke direclty, then there is no relation between those two jsp pages.
Looks like you are directly printing the values without checking whether headname is having a valid value (and NOT null).
If for some case, the headname is null you would get the NPE. Yes, that is what you are getting.
Did you ensure that you get the selected options in A.jsp? What are you geting in A.jsp through your out.println?
Amit is right I am just giving the quick solution here.
here we go,
The following line of code in A.jsp
is of no use as String select = request.getParameterValues("id");
will always return null.
replace the code you have in B.jsp with this and it will work only remove the
I hope this helps
if you figured this out already then good.
Just to summarize,
You are actually trying to pass few values from one page to another (say, a.jsp to b.jsp).
In your a.jsp itself, you are doing the following.
1. Obtaining the list of values from the request object with the key "id" and stuff them into an array of Strings (select).
2. Setting / Binding the gathered values (select) into the request object with the key "idvalues".
Next in b.jsp, you are trying to obtain the same set of values through the same key "idvalues" to which you had bound the request values.
The mistake comes in your a.jsp itself. Wherein, you are trying to fetch the passed values through the key "id" from the request object. Ideally there is no request object existing at that point of time (when the page is getting executed/rendered) until you submit it! Hence, the return value what you get out of "id" is null. So nothing would be accumulated into "select". You are indeed binding the null value to "idvalues" and it gives the same null in b.jsp.
That's why you get a NPE (Null Pointer Exception).
As the previous poster said, you can very well avoid the manual transformation from "id" to "idvalues" in a.jsp. Rather you obtain the same set of values in b.jsp with the same key for the checkboxes that is "id". It will work fine.
Hope this explanation helps!
Dinesh Remje wrote:Thanks Amit actually i accidentally figured it out. But anyway thanks for your help. But can you tell me how those values get transfered in B.jsp page i mean how the value of id gets transfered to B.jsp.
That is the magic of your request object! That's where the object comes in picture!!
You are actually forwarding a request from a.jsp to b.jsp (through your form action tag) and the checkboxes whatever you had selected are available as part of the present request object. You are fetching the values using the "request" object.
Remember, request is one of the 9 implicit objects in JSP! The container (Servlet/JSP engine) does the work of putting the values into request object! so you don't need to anything!