• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

URL encoding of Scandinavian alphabet

 
Greenhorn
Posts: 20
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 15484
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for reporting back with your findings.

Have a cow.
 
Saloon Keeper
Posts: 27752
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Once upon a time there were three bears. And they were visted by a golden haired tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic