Meaningless Drivel is fun!*
The moose likes JSP and the fly likes can i send  character encoding with the url Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "can i send  character encoding with the url" Watch "can i send  character encoding with the url" New topic
Author

can i send character encoding with the url

Essam AbdelAziz
Ranch Hand

Joined: Mar 10, 2007
Posts: 34
hi
can i send character encoding with the url

for example

URL="/app/Myservlet?character-encodin=UTF"
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39542
    
  27
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.


Ping & DNS - updated with new look and Ping home screen widget
Essam AbdelAziz
Ranch Hand

Joined: Mar 10, 2007
Posts: 34
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
Marshal

Joined: Mar 22, 2005
Posts: 39542
    
  27
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

Joined: Mar 10, 2007
Posts: 34
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
Marshal

Joined: Mar 22, 2005
Posts: 39542
    
  27
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

Joined: Mar 10, 2007
Posts: 34
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

Joined: Mar 10, 2007
Posts: 34
i use this in my servlet but no effect
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60046
    
  65

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Essam AbdelAziz
Ranch Hand

Joined: Mar 10, 2007
Posts: 34
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

Joined: Mar 10, 2007
Posts: 34
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

Joined: Mar 10, 2007
Posts: 34
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
Marshal

Joined: Mar 22, 2005
Posts: 39542
    
  27



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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: can i send character encoding with the url
 
Similar Threads
platform's default character encoding
changing oracle application server URL encoding
changing oracle application server URL encoding
Different behavior between getWriter and getOutputStream
character encoding problem