• Post Reply Bookmark Topic Watch Topic
  • New Topic

Passing array from servlet to JSP  RSS feed

 
caba jones
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a servlet, in which i have an array i want to pass the array value to jsp with out any form action.
 
Tim Moores
Saloon Keeper
Posts: 3834
80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You would use the setAttribute method before forwarding the request to the JSP.
 
caba jones
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am getting only null value in the jsp
 
Dave Tolls
Ranch Hand
Posts: 2839
30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You might need to show the code for both the set in the servlet and how you are accessing the array in the JSP.
 
caba jones
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can you please post some sample code
i have iarray[i] this contains some values,i am trying to set in session
like
session.setAttribute("iarray[i]",iarray[i]);
and get it in jsp like session.getAttribute("iarray[i]");
but getting only null
 
Dave Tolls
Ranch Hand
Posts: 2839
30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Normally you would set it on the request, unless you needed to maintain it between requests.

Also, that's storing an element in an array, not the array.
Finally that's an odd choice of name.
Why not:


then you can get that on the JSP via JSTL or el...you shouldn't have any Java on the JSP page.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!