Question

Using GWT, I've got a webapp, and on a certain page it pulls a parameter from the URL that has the pipe character (|) encoded. So, for example, the full URL would be (in dev mode):

http://127.0.0.1:8888/Home.html?gwt.codesvr=127.0.0.1:9997#DynamicPromo:pk=3%257C1000

and when I pull the parameter "pk" I should get "3|1000". (%257C is the encoded pip char)

Well, this works just fine in Firefox and Chrome.

In IE (I'm using 11), I get "3%7C1000" when I pull the parameter. For whatever reason, IE drops the 25 in the encoded character, meaning it's no longer a pipe char and my app breaks.

I've read around and found that encoding issues are common on IE. In particular, I found this page: http://support.microsoft.com/kb/928847

It's suggested solutions include:

  • Disable the Auto-Select setting in Internet Explorer.
  • Provide the character set in the HTTP headers.
  • Move the META tag to within the first kilobyte of data that is parsed by MSHTML.

I've tried those 3 and it didn't help. Here is the beginning of my Home.html:

<!doctype html>

<html>
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />    
    <meta http-equiv="content-type" content="text/html;charset=utf-8" />

The other two suggestions:

  • Increase the size of the server's initial HTTP response. The initial size should be at least 1 KB.
  • Make sure that the System Locale setting matches the character set of the META tag that is specified in the HTML page.

I don't feel will do anything. My system locale settings are correct. And since my meta tags are at the beginning of the document, they are within the first kilobyte of data, so they would be read first. So I don't see why I'd need to increase the HTTP response size.

So, I need IE to properly read this encoded character for the web application to work properly. Does anyone have any other suggestions I could try?

UPDATE:

How the URL is encoded:

URL.encodePathSegment(place.getValue())

Where URL is from the package com.google.gwt.http.client

getValue() is set from this:

public static String encodePk(PrimaryKey pk)
{
    if(pk != null)
    {
        return String.valueOf(pk.getPk()).concat("|").concat(String.valueOf(pk.getCpk()));                    
    }
    else{
        return "";
    }        
} 

The final result is the url I posted at the top:

http://127.0.0.1:8888/Home.html?gwt.codesvr=127.0.0.1:9997#DynamicPromo:pk=3%257C1000

Where the part after "pk=" is the encoded string.

Was it helpful?

Solution

In order to make sure IE kept the encoding in tact, I had to first decode the URL as soon as I set it:

public void setValue(String value)
{
    this.value = unescape(value);
}

private static native String decodeURI( String s )
/*-{
    return decodeURI(s);
 }-*/;

Thanks a lot for the help!

OTHER TIPS

Try JavaScript encodeURIComponent() Function to encode a string. This function makes a string portable, so it can be transmitted across any network to any computer that supports ASCII characters.

This function encodes special characters.

In addition, it encodes the following characters: , / ? : @ & = + $ #


For more info click HERE.

Here is a sample code using JSNI:

public static final native String encodeURIComponent(String uri) /*-{
    return encodeURIComponent(uri);
}-*/;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top