wood burning stoves 2.0*
The moose likes Struts and the fly likes Struts and dynamic image sources. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts and dynamic image sources." Watch "Struts and dynamic image sources." New topic
Author

Struts and dynamic image sources.

Roger Moore
Greenhorn

Joined: May 31, 2005
Posts: 3
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

Joined: Apr 14, 2005
Posts: 354
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.


-/a<br />certified slacker...yes, my last name is 'do' - <a href="http://www.luckycouple.com" target="_blank" rel="nofollow">luckycouple.com</a>
Roger Moore
Greenhorn

Joined: May 31, 2005
Posts: 3
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

Joined: Apr 14, 2005
Posts: 354
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

Joined: May 31, 2005
Posts: 3
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

Joined: Apr 14, 2005
Posts: 354
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.
 
jQuery in Action, 2nd edition
 
subject: Struts and dynamic image sources.
 
Similar Threads
retrieve multiple images from mysql
Display image on jsp page
problem with server relative paths for images
to get all required fields in single page
Giving a URL for File