This week's book giveaway is in the Functional programming forum.
We're giving away four copies of Functional Design and Architecture and have Alexander Granin on-line!
See this thread for details.
Win a copy of Functional Design and Architecture this week in the Functional programming 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:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

What happens enctype="" for URLEncoder.encode(String url, string enctype)

 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,
Could you please let me know the difference between URLEncode.encode(Staring urlname) and URLEncoder.encode(String url, ""<Not specified any encrypt type>) from 1.4 to 1.5...

Thanks,
Rajesh Yarlagadda
 
Marshal
Posts: 22441
121
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When you don't specify the encoding the system default encoding will be used. While that may not be a problem for files (usually), on the web you cannot make such assumptions. That's why the overloaded method without an explicit encoding has been made deprecated.
 
rajesh babu Y
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For URLEncoder.encode(string url) takes the UTF-8 as default encoding type, then now, if i go with URLEncoder.encode(string url, ""<not specifying any encoder type, just gave empty string>) is it will take the default or not perform the operation ?

from the java api docs i read that URLEncoder.encode(string url) takes if an encoding is not specified, then the default encoding of the platform is used. How the encoding is differentiated from each platform ?

Thanks,
Rajesh
 
Rob Spoor
Marshal
Posts: 22441
121
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

rajesh babuy wrote:For URLEncoder.encode(string url) takes the UTF-8 as default encoding type


No it doesn't. It takes the system's encoding. On Windows that's usually Windows-1252 which is closely related to ISO 8859-1. It's definitely not UTF-8.

then now, if i go with URLEncoder.encode(string url, ""<not specifying any encoder type, just gave empty string>) is it will take the default or not perform the operation ?


If you provide an empty String then I expect (and actually get) an UnsupportedEncodingException. You need to provide a supported encoding, e.g. UTF-8.

from the java api docs i read that URLEncoder.encode(string url) takes if an encoding is not specified, then the default encoding of the platform is used. How the encoding is differentiated from each platform ?


For me it would be Windows-1252. For someone in Russia using Windows it's more likely to be Windows-1251. It all depends on the operating system and system language. Because the encoded values are usually sent between systems with possible different encodings, it's very unwise to use the system default encoding. By explicitly specifying the encoding you will ensure that both sides will use the same encoding.
 
rajesh babu Y
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm working on one application which is now running on unix machine, webshpere 5.0 server with java 1.4 and j2ee1.3. In my code we are using URLEncoder.encode(String url).

Now i have requirement to change the application configuration to another(like linux, Webshpere 6.1, java 1.5 and j2ee 1.4 ). when i compile the java files i got the warning URLEncoder.encode(String url) is deprecated.

we are working on windows machines and the application located in linux machines. how do i come to know which encoding type it is using ?

If i gave URLEncoder.encode(String url, String encodetype<UTF-8>) and deployed my application on linux machines what happens, is it throws UnsupportedEncodingException or is it take the platform specific encoding type? is there any way to take the default encoding type base on platform ?

Sun systems won't provide any default encoding type, it's based on platform. How i can move ahead to get my application without warn messages from these deprecated methods?

Thanks,
Rajesh

 
Rob Spoor
Marshal
Posts: 22441
121
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The method has been deprecated since Java 1.4, so you should have seen the deprecation warning before. As for the default encoding, you can see that by calling Charset.defaultCharset().name().
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic