• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

images in HTML/JSP

 
Ranch Hand
Posts: 173
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi folks,

This is a pretty general question and I hope I am in the appropraite forum.

In HTML one can display an image with the following code:

<img src="path/image.jpg" width = "70" height="100" />

Now, if I want to display an image in a jsp and then use some logic to redisplay a second image in the same location on the page, how do I do it? The above is hard coded. In a jsp I cannot build a string and then display it, i.e.

<% String i1 = "path/image1.jpg";
String i2 = "path/image2.jpg";

.. some logic to assign either i1 or i2 to s..

String h = "<img src=" + s + "width=/""70" ... etc;
%>

as you see, although I have built a String, the HTML bit is still text. I can't think of a way of parameterising the HTML. I thought of actually writing different images into the file located at

path/image.jpg

but this feels wrong, since in web apps generally, writing to the deployed files is not usually recommended.

So, how does one display different images on a page?

with best regards,
Simon Ingram
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

In a jsp I cannot build a string and then display it, i.e.

<% String i1 = "path/image1.jpg";
String i2 = "path/image2.jpg";

.. some logic to assign either i1 or i2 to s..

String h = "<img src=" + s + "width=/""70" ... etc;
%>



Why not? What prevents you from doing this? If the logic to decide between i1 and i2 can be decided in the server, then you can use JSP. If it depende on something on the client, or if you want to change images once the page has been generated and served to the browser, then you need to use a JavaScript solution.
 
Simon Ingram
Ranch Hand
Posts: 173
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ulf,

the logic is on the server. the problem is not making the decision, it is the technical matter of displaying different images on a web page. Imagine the page shows some playing cards (jpeg files). Is it possible to keep the table static and use the servlet to write different images (cards) to the same location on the page? I can't see how to get round the fact that the HTML is not flexible.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic