• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to send a value from one JSP page to another without a form?

 
Ben Coleman
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am uploading data from an external database and displaying them on my page. All the Strings are loading fine and images too but I get the same image (last image in database row) instead of different images each time I loop. I need a way to pass my "id" value from one page to another to be able to construct my SQL query directed to the correct id.

I have tried by using a simple class with a static String and store/change its value on each iteration of the loop so I can call it anywhere.
I have tried using sessions by setting its attribute on each iteration.

Tried printing the value of both these methods and they only return the value of 19 once (id of last image row).

I have also tried using a hidden input and setting its value and try to get that value at image.jsp. This doesn't work as I am not using a form.

Thus how can I send the updated id value from the first page to image.jsp each time I loop?

First Page



image.jsp

 
Dave Tolls
Ranch Hand
Posts: 2373
25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


That src link should include something like:


Though I'm not sure what's going on in that other JSP.

That image.jsp won't work...it can't return the image as the servlet engine has already started returning HTML.
It should (has to in fact) be a servlet.
 
Ben Coleman
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dave Tolls wrote:

That src link should include something like:


Though I'm not sure what's going on in that other JSP.

That image.jsp won't work...it can't return the image as the servlet engine has already started returning HTML.
It should (has to in fact) be a servlet.


For some reason, I am using image.jsp?id=resultset.getString(7) and over at image.jsp calling that value via getParameter("id") and it is working now.
 
Dave Tolls
Ranch Hand
Posts: 2373
25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh well, that's nice.

Surprising as I would have though the response would already have started, and the <body> tags would at least muck up rendering of an image.

It's still not something that should be in a JSP, though.
 
my overalls have superpowers - they repel people who think fashion is important. Tiny ad:
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!