0

I have an object tag that I'm using its data attribute to call a servlet like the code bellow. I'm passing a parameter to this url . in case the value of this parameter is not english > arabic for example. then when I get this parameter value in the specified servlet > its value looks something like this "يجب التØÙ‚Ù‚ من.pdf"

I tried to add some other query string parameter like &&useUnicode=yes&&characterEncoding=UTF-8 to the url but with no luck. I also tried to use some code like request.setCharacterEncoding("UTF-8"); to the servlet but with no luck too.

this is how my code look like :

<object data="servletName.ex?fileName=${fileNameValue}">click</object>

I want to get the arabic value as it is when i get the value of the file name parameter.

  • 2
    Possible duplicate of [How to URL encode a URL in JSP?](https://stackoverflow.com/questions/15923062/how-to-url-encode-a-url-in-jsp) – Jasper de Vries May 13 '19 at 14:01

1 Answers1

0

You need to URL-encode fileNameValue. You cannot tell the server which encoding to use for the URL by adding this info to the URL. The server needs to know BEFORE it reads the query - which is not possible. ;) Nowadays, you can safely assume that the server expects UTF-8. Makes sense - it should be prepared to understand those 2-byte Unicode Sequences. The only catch: URLs are not allowed to contain those characters. This is the reason for URL-Encoding / percent escaping.

If your filename would be "Über" - your request would be: "%C3%9Cber". This is a 2-byte url-encoded utf-8 encoded value of that first special character.

Mick
  • 954
  • 7
  • 17