Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Struts and dynamic image sources.

 
Roger Moore
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi There,
I'm working on an application prototype for a product invenory system.
Part of each products details includes several images (thumbnail, collection of vehicle images).
Image locations (url) are stored in a database and loaded as part of each product image, however, when the image urls are placed within the HTML image SRC tag, the image doesnt display.

1. My html IMG tag is correct.
Generated Tag :
<img src=�http://127.0.0.1:8080/vehicleStruts/testImages/17512_1_th.jpg" alt=�http://127.0.0.1:8080/vehicleStruts/testImages/17512_1_th.jpg� width="100" height="70">
I can copy and past the generated URL into another browser window and pickup the image.

2. My Struts logs state :
ERROR [RequestProcessor] Invalid path /�??http:/127.0.0.1:8080/vehicleStruts/testImages/17512_1_th.jpg" was requested

Has anyone encountered this situation or have any ideas?

Thank.
Rog
 
alan do
Ranch Hand
Posts: 354
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the error shows that you have a single slash after the http: (hope you copied and pasted the error message).

regardless, when refering to images that is in a known directory (same goes for shared files such as .css and .js), it's best to use a '/' follows by your application context root then your image directory relative to the context root. in your case it would be "/vehicleStruts/testImages/17512_1_th.jpg" (without the full server name). this is especially helpful when you move application from dev to QA to production. it's also helpful in the case where server name/ip/dns mapping may not be what they appear to be.
 
Roger Moore
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for that.
The server hosting the vehicle graphic will not necessarilly be the sturts app hosting server. How should I handle that ?
(Also, yes its a copy and paste, the app log shows 1 / but the string written to the generated jsp page has // (as shown in 1 above.)

Thanks,
Rog
 
alan do
Ranch Hand
Posts: 354
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
fully qualified URL is necessary in that case.

i am now not sure why the single slash is showing in the error and the "�??" right after it. how did you obtain the server base url? if you hard coded it, could it be that your editor/ide somehow converts the second slash into those weird charaters?
 
Roger Moore
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The URL (in full) is pull back from a db record.

I'm using CMP with a session facade exposed to the struts application.

I make no changes to the string pulled from the DB. Despite the wierd logs... the img src is written correctly to the IMG tag in the generated JSP. I've copied and pasted it into a browser window and the image loads. (lots of head scratching for my part as a result)


Rog.
 
alan do
Ranch Hand
Posts: 354
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it must be the DB encode vs. Java decode...i think. copy from the source and paste it in the browser does not copy the encode/decode as stuff (i really hate) go on behind the Java scene.

can you strip the first 7 characters from the URL in your java code and prepend the http:// as a string after stripping it? if it's some weird de/encoding issue, you'll know.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic