tags:

views:

89

answers:

3

Hi,

I created a static jsp page with an image whose src is set to num%C2%B2.jpg (actual name of the image is num².jpg ) But apache is not able to locate the image..

I googled for a sample application and found an image gallery- https://jgallery.dev.java.net/ but even this application breaks for num².jpg

what could be the problem?

A: 

As you can see, the ² has been encoded as two characters - %C2%B2. This means that you're probably encoding the filename in unicode. You need to make sure that when you read the file back from the filesystem that unicode is used too.

I'm not a java programmer so that's as far as I can help you, but it definitely seems to be an encoding issue. You could try converting it to ASCII before you url encode it...

A quick test would be to put “num%B2.jpg” in your address bar and see if it works.

Greg
I need to support images with Arabic and Chinese characters as wellThanks for your help though :)
James_Smith
+1  A: 

Use <@page encoding> tag (or <% response.setCharacterEncoding %> in ) your JSP to change the encoding to Latin 1 or whatever your Apache expects.

However, this may break some other characters on your page (outside the selected character set).

EDIT: Or, URL-Encode your URL before you insert it into the JSP. java.net.URLEncoder or JSTL's <c:url> could be used to do that.

david a.
tried that..but even that didn't workI had to add URIEncoding="UTF-8" in connector setting in server.xmlthis solved the problem..but raised another..I can't always control the environment in which my application runs..
James_Smith
+1  A: 

I had to add URIEncoding="UTF-8" in connector setting in server.xml under apache tomcat

James_Smith
That's correct.
BalusC