Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

URL encoding of Scandinavian alphabet  RSS feed

 
Greenhorn
Posts: 20
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!

I have a problem with the query part of my URL:s on my website. I need to use Scandinavian alphabet in the query /parameters part (like [mydomain]?name=Räty). When I'm running my server code on my home computer, I have no problem with them. But when deployed to a US based hosting service, they do cause a problem.

I'm using c:url in my JSP:s and it encodes my parameters, but not Scandinavian alphabet. First question is am I supposed to encode them? Google search of URL encoding only produced instructions saying alphanumeric characters don't need to be encoded. But how about non-English alphabet?

Or is this a problem with the character encoding of my Tomcat server? I have a CharacterEncodingFilter set to UTF-8 in my Spring MVC web.xml. Do I need to do something with my Tomcat settings?

If I need to encode non-English alphabet, how do I do this in JSP and what do I need to do on server side in my Spring MVC-server code to decode the query parameters?
 
Saloon Keeper
Posts: 9118
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you show us some of the related code, and describe the exact problem that's being caused?
 
Jarno Virta
Greenhorn
Posts: 20
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Stephan van Hulst wrote:Can you show us some of the related code, and describe the exact problem that's being caused?



Well my question was mostly general. Am I supposed to encode those characters? I'm wondering this because <c:url> tag does do encoding but doesn't do anything to characters like Ä or Ö.

I've since tinkered with my code and I got everything to work. I did add encoding for those characters. But the code in the JSP is quite ugly. This is how I got the necessary parameters encoded:



So I used URLEncoder.encode() for encoding the parameter. But I couldn't just put it into <c:url> value attribute or the %'s would get encoded. I got around it using <c:set>. This looks way too complicated, though.

And I'm still wondering if it is generally good practice/recommended to encode those characters? Or is what I just did pointless?

In the end the problems I was having weren't due to me not encoding those characters, I think. The problem was that the production Tomcat server needed to be set to UTF-8 by adding URIEncoding="UTF-8" to the Connector tag in server.xml. This fixed it.

But I'm still wondering if I should keep the characters encoded or if its generally ok to have Ä's and Ö's and such in parameters?
 
Jarno Virta
Greenhorn
Posts: 20
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well now I feel silly. <c:url> does take care of those Äs and Ös, the link is shown in browser as decoded text of course so I thought it did nothing to those. So it was all just a problem with server configuration. How silly. Oh well...
 
Author and ninkuma
Marshal
Posts: 66783
168
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for reporting back with your findings.

Have a cow.
 
Bartender
Posts: 19656
92
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Helpful hint: URL syntax allows you to swap out characters for their hex values. You most commonly see this in query parameters such as "?date=next%20week", where the "%20" eliminates the problem of having a space in the middle of a URL query string.

Since the displayed values of characters in a console window can vary depending on the code page it has selected, sometimes what you type isn't what the server expects. You can eliminate this problem by using the hex value of the character that the server actually wants.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!