views:

340

answers:

3

Hi,

I am trying to display some images containing special characters like ☻ ☺ ♥ or Chinese or Arabic characters in their names using jsp...but the images are not getting displayed !!

<img src = "pipo².jpg" />
<img src = "pip☺☻♥o².jpg" />

What am I doing wrong !!

+2  A: 

Try encoding the filename using URLEncoder.encode() method before the HTML is sent to the page, e.g.

String encodedString = URLEncoder.encode(filename, "UTF-8").

This will convert the characters to entities which can be passed in HTML.

Alistair Knock
pip².jpg is converted into pip%C2%B2.jpgand its still isn't working :(
James_Smith
A: 

you can percent encode the urls using encodeURIComponent in javascript to give you

<img src="pip%C3%A2%C2%98%C2%BA%C3%A2%C2%98%C2%BB%C3%A2%C2%99%C2%A5o%C3%82%C2%B2.jpg">
cobbal
pip².jpg is converted into pip%C2%B2.jpg with encodeURIComponent and its still isn't working :(
James_Smith
you have pipo².jpg, not pip².jpg in the OP, or is one of those a typo?
cobbal
yea..it was a typopipo².jpg is converted to pipo%C2%B2.jpginstead of encodeURIComponent I used escape()..and I image got loaded.escape() converted pipo².jpg into pipo%B2.jpgbut escape doesn't work with Arabic or Chinese characters :(
James_Smith
I wrote a small application in .NET..i set the image source to "pipo².jpg" and it got converted into pipo%C2%B2.jpg.. and this seems to work great !! which means there's something wrong with my html page ..trying to find out what exactly is it
James_Smith
I think I narrowed down the issue..i probably have to configure something in my java application or tomcat..so that it supports characters like
James_Smith
I had to change the server.xml and add URIEncoding="UTF-8"
James_Smith
A: 

I'd recommend renaming your files.

Using special characters in src paths is not strictly allowed, you'd have to find the URL style escape codes for those characters.

Kurley