Loading...
Important Notice - Forums is archived

To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Product icon
TUTORIAL

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.

get encoded url request value

JJ CHEN
10 years ago Mar 15, 2012 1:28pm
Basil Bourque
10 years ago Mar 23, 2012 7:37pm

(a) 'C4' is not the character you are looking for.

'C4' hex for decimal 196, which in Unicode is the character:
LATIN CAPITAL LETTER A WITH DIAERESIS
Looks like: Ä

Apparently you want C5 (197):
LATIN CAPITAL LETTER A WITH RING ABOVE
Looks like: Å

Tip: If you use Mac OS X, I highly recommend downloading the free app UnicodeChecker to see a complete database of Unicode characters.

(b) I am not having any problem retrieving URL parameters containing U+00C4 & U+00C5 Uniccode characters.

I am using plain Java 6 and the Vaadin 6 ParameterHandler class running in Eclipse Indigo using it's built-in web browser (WebKit based, as I understand it).

Here is a simple example app that dumps the URL parameter to the console. Simply copy-paste this code as a complete Vaadin 6.7.6 app.

This URL:
http://localhost:8080/ExampleVaadin/?param1=value1&param2=v%C4lue2&param3=v%C5lue3
Outputs this to the console:
DEBUG - Dumping map of 3 URL paramaters to console. Fri Mar 23 12:21:33 PDT 2012
param1 yelds 1 values ---> [value1]
param2 yelds 1 values ---> [vÄlue2]
param3 yelds 1 values ---> [vÅlue3]

package com.example.examplevaadin;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
import java.util.Map;

import com.vaadin.Application;
import com.vaadin.data.util.ObjectProperty;
import com.vaadin.data.util.PropertyFormatter;
import com.vaadin.terminal.ParameterHandler;
import com.vaadin.ui.*;

/**
 * This complete Vaadin 6.7.6 app demonstrates how to access any URL parameters.
 * Most Vaadin apps do not use any URL parameters. But you may want to for special cases.
 * See section 12.5.2 "Parameter Handlers" in the Book of Vaadin for more info.
 * https://vaadin.com/book/-/page/advanced.resources.html
 * 
 * © 2012 Basil Bourque. This source code may be used freely forever by anyone taking full responsibility for doing so.
 * @author Basil Bourque. 
 *
 */
public class ExamplevaadinApplication extends Application {

    @SuppressWarnings ( { "serial", "unchecked" })
    @Override
    public void init() {
        Window window = new Window( "Examplevaadin Application" );
        Label label = new Label( "Look at console or logs to see list of parameters passed on URL." );
        window.addComponent( label );
        
        Label label2 = new Label( "Try a URL like: " + "http://localhost:8080/ExampleVaadin/?param1=value1&param2=value2&param3=value3" );
        window.addComponent( label2 );
        
        Label label3 = new Label( "Or try some Unicode in your URL: " + "http://localhost:8080/ExampleVaadin/?param1=value1&param2=v%C4lue2&param3=v%C5lue3" );
        window.addComponent( label3 );

        UrlParameterDumper dumper = new UrlParameterDumper();
        window.addParameterHandler( dumper );

        setMainWindow( window );
    }

}

/**
 * Demonstrates dumping URI parameters to the console.
 */
 class UrlParameterDumper implements ParameterHandler {

    /**
     * Implement the method required by the ParameterHandler interface.
     */
    public void handleParameters( Map< String, String[] > parameters ) {
        // Dump map of parameters to console.
        System.out.println( "DEBUG - Dumping map of " + parameters.size() + " URL paramaters to console. "
                + new java.util.Date() );
        Iterator< String > iterator = parameters.keySet().iterator();
        while ( iterator.hasNext() ) {
            String key = iterator.next().toString();
            String[] valuesArray = parameters.get( key );
            ArrayList< String > valuesList = new ArrayList< String >( Arrays.asList( valuesArray ) ); // For easy printing, convert array to a Collection.
            System.out.println( key + " yelds " + valuesList.size() + " values ---> " + valuesList );
        }

    }

}


Last updated on Mar, 23rd 2012