GeoNames Home | Postal Codes | Download / Webservice | About 

GeoNames Forum
  [Search] Search   [Recent Topics] Recent Topics   [Groups] Back to home page 
[Register] Register / 
[Login] Login 
Encoding problem when using Java client  XML
Forum Index -> General
Author Message
Dimi



Joined: 29/07/2009 14:52:31
Messages: 2
Offline

Hi all,

I'm using the geonames Java client to find a city with the given postal code and country. I am having problems with umlauts - I'm getting ?-signs instead of the correct umlaut - K?ln instead of the correct Köln.

My code looks like:

PostalCodeSearchCriteria pcsq = new PostalCodeSearchCriteria();
pcsq.setCountryCode("DE");
pcsq.setPostalCode("50667");
List<PostalCode> foundList1 = WebService.postalCodeSearch(pcsq);
for (PostalCode postalCode : foundList1) {
System.out.println(postalCode.getPlaceName());
}

Any ideas?
Thank you very much in advance!

Dimi
marc



Joined: 08/12/2005 07:39:47
Messages: 4501
Offline

Hi Dimi

When I copy paste your code and run it then I get 'Köln' with the correct Umlaut.

Best

Marc

[WWW]
Dimi



Joined: 29/07/2009 14:52:31
Messages: 2
Offline

Hi all and thank you Marc for your reply!

So, I solved it!

The problem was the incorrect encoding of the response-object of the servlet:

.....
PostalCodeSearchCriteria pcsq = new PostalCodeSearchCriteria();
pcsq.setCountryCode("DE");
pcsq.setPostalCode("50667");

List<PostalCode> foundList = WebService.postalCodeSearch(pcsq);
.....
response.setCharacterEncoding("UTF-8"); //this line solved the problem
//returnObject is an JSON object
response.getWriter().write(returnObject.toString());

I hope this helps someone, who tries to implement autocompletion using a servlet and the geonames Java client

Dimi
 
Forum Index -> General
Go to:   
Powered by JForum 2.1.5 © JForum Team