reading jsp array in to java(servlet) program

Thread Solved

Join Date: Aug 2009
Posts: 26
Reputation: beanboy is an unknown quantity at this point 
Solved Threads: 1
beanboy beanboy is offline Offline
Light Poster

reading jsp array in to java(servlet) program

 
0
  #1
Sep 24th, 2009
hi helpers,
i'm trying to read an array from jsp in to java(servlet) page
the code is
JSP CODE (readingcheck box values):
  1. String select[] = request.getParameterValues("sel");
  2.  
  3. if (select != null && select.length != 0) {
  4.  
  5. for (int i = 0; i < select.length; i++) {
  6. out.println(select[i]);
its working ok!

JAVA CODE(reading array values):
  1. String select2[] = request.getParameterValues("select");
  2. for (int i = 0; i < select2.length; i++)
  3. {
  4. System.out.println(select2[i]);
  5. }
the above java code didnt worked.

i also tried this
  1. String[] select= new String[100];
  2. for (int i = 0; i <10 ; i++)
  3. {
  4. select[i] = request.getParameter(select[i]);
  5. System.out.println(select[i]);
  6. }
this didnt worked too
is there any other way to read array values from jsp page?
where am i wrong?

thanks,
BeanBoy !
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 318
Reputation: Thirusha is an unknown quantity at this point 
Solved Threads: 51
Thirusha's Avatar
Thirusha Thirusha is offline Offline
Posting Whiz

Re: reading jsp array in to java(servlet) program

 
0
  #2
Sep 25th, 2009
getParameter only works if the parameter you are accessing exists in the URL that was sent to the servlet.

Are you sure that the array is being sent to the servlet?

If the url is this : "/jspservlet?name=blah&myArray={1,2,3}" (the curly brackets would be replaced with the correct url encode for brackets which would be %something), then using request.getParameter("myArray") would return the array.
Life... Is a Moment
Reply With Quote Quick reply to this message  
Join Date: Aug 2009
Posts: 26
Reputation: beanboy is an unknown quantity at this point 
Solved Threads: 1
beanboy beanboy is offline Offline
Light Poster

Re: reading jsp array in to java(servlet) program

 
0
  #3
Sep 25th, 2009
Originally Posted by Thirusha View Post
getParameter only works if the parameter you are accessing exi..........."myArray") would return the array.
its working ! thanks
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 318
Reputation: Thirusha is an unknown quantity at this point 
Solved Threads: 51
Thirusha's Avatar
Thirusha Thirusha is offline Offline
Posting Whiz

Re: reading jsp array in to java(servlet) program

 
0
  #4
Sep 25th, 2009
Pleasure, glad to help
Life... Is a Moment
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:




Views: 759 | Replies: 3
Thread Tools Search this Thread



Tag cloud for JSP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC