Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Problem with URLEncoder.encode and request.getparameter with chinese characters

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is the URL that I use to invoke my servlet from my applet

Code:

http://192.168.0.67/MyServlet?p1=団

As you can see, the parameter has a unicode character 団. So I use

Code:

URLEncoder.encode ( "団", "UTF-8" ) ;

and now my URL becomes

Code:

http://192.168.0.67/MyServlet?p1=%E5%9B%A3

However, from the servlet, calling

Code:

request.getParameter ( "p1" ) ;

already return some gibberish that cannot be decoded with URLDecoder. BTW, invoking

Code:

URLDecoder.decode ( "%E5%9B%A3", "UTF-8" ) ;

does give me the original unicode character. It`s just that the servlet has garbled the parameter before it can even be decoded. Does anyone know why?

Request.gerparameter doesnt decode parameter with UTF-8?
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

You need to translate the character set of the parameter

Ex:


Its just an example iso code, you need to find the correct one for Chinese.
 
WHAT is your favorite color? Blue, no yellow, ahhhhhhh! Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic