Jayesh
Jayesh

Reputation: 25

Alternatives to encode URL

I am trying to encode input form data here. There are two options and I have tried both of them:

  1. Use URLencoder.encode(inputString) method which does not work on GWT client side (My code resides in client module) Results in error 'Did you forget to inherit required module?'
  2. URL.encodeQueryString(inputString) which works well, But when I run relevant test cases using JUnit, all I get is unsatisfiedlinkederror

Are there any alternatives for encoding method or is there any work around for above mentioned methods?

Upvotes: 0

Views: 3501

Answers (3)

Churro
Churro

Reputation: 4366

For URL building, I use the "UrlBuilder": com.google.gwt.http.client.UrlBuilder

UrlBuilder u = new UrlBuilder();
u.setProtocol("https");
u.setHost("www.mysite.com:8080");
u.setPath("/myServletPath");
u.setParameter("username", nameField.getValue());
u.setParameter("someAttribute", "itsValue");
u.buildString();

This code will result in: https://www.mysite.com:8080/myServlet?username=GWT%20User&someAttribute=itsValue

Upvotes: 0

Andrea Boscolo
Andrea Boscolo

Reputation: 3048

Just use the URL class and its methods:

Do not forget to inherit the required module <inherits name="com.google.gwt.http.HTTP"/>.

Upvotes: 0

user2508244
user2508244

Reputation: 91

For your second option : GWT uses modules and needs to be compiled, which is different than running a simple JUnit test. Take a look at http://www.gwtproject.org/doc/latest/DevGuideTesting.html, they explain how to setup JUnit test.

Upvotes: 1

Related Questions