• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

can i send character encoding with the url

 
Essam AbdelAziz
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi
can i send character encoding with the url

for example

URL="/app/Myservlet?character-encodin=UTF"
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That will not work. If that's the URL that a form gets submitted to, then the browser will generally use the same encoding that was used by the page containing the form.

Also note that "UTF" is not a valid encoding - "UTF-8" or "UTF-16" is.
 
Essam AbdelAziz
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
so what can i do in this case

i need to call the servlet from my jsp like this

Form.action="myservlet?Name="+'engleshname'
in this case the servlet will recieve the name with no problem and print it correctly
but if
Form.action="myservlet?Name="+'arabicname'
in this case the servlet will recieve the name
but when i try to print it will print ???


in jsp i set charcter encoding like this



in servlet


thanks
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In an URL you'll need to URL-encode the values; have a look at the HttpServletResponse.encodeURl method. To avoid confusion, consider making the parameter a hidden field of the form, instead of an URL parameter.
 
Essam AbdelAziz
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
consider making the parameter a hidden field of the form, instead of an URL


for abusiness need i can't do that
is there any solution
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
for a business need i can't do that


The format of a URL used in a form post can't really be a business need, can it? Maybe there's a technical reason that can be overcome?

Have you tried URL-encoding?
[ March 28, 2007: Message edited by: Ulf Dittmer ]
 
Essam AbdelAziz
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry i can't express my self well
you right it's technical reason
i use ajax
and call the servlet from js file so i just can use the url

what you mean by url encodin?


is there any way?
 
Essam AbdelAziz
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i use this in my servlet but no effect
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64959
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Essam AbdelAziz:

i use ajax
and call the servlet from js file so i just can use the url


You need to brush up on your Ajax know-how. You can easily use Ajax to make either POST or GET requests.

The limitation is not with the technology, but with your knowledge of it.
 
Essam AbdelAziz
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
could you please le me how to set the charcter encoding
i know the problem with XMLHTTPRequest

how to set teh charcter encoding with UTF-8

thanks
 
Essam AbdelAziz
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i tried this
but no effect and still stuck

request = new XMLHttpRequest(); /* Firefox */

request.overrideMimeType("text/html; charset=UTF-8");


thanks
 
Essam AbdelAziz
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
is any body there
i'm still stuck and no solution

i tried not to use ajax




when i tried to get the value from servlet also i have ???

also





thanks
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



when i tried to get the value from servlet also i have ???

also


[/QB]


Let's leave AJAX aside for the moment, and just consider forms.

The first thing to find out is which encoding is used by the page containing the 'handleEdit' function above. That's important because that encoding will be used for submitting the form. If that page was generated using "response.setContentType("text/html; charset=UTF-8");", then it should be submitted in UTF-8.

What are the actual bytes that arrive at the servlet? I am guessing that the '???' were printed to a console or a log, which may well not support Unicode.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic