编码URL的替代方案

时间:2013-07-28 21:47:09

标签: java gwt encoding

我正在尝试对输入表单数据进行编码。有两个选项,我尝试了两个选项:

  1. 使用URLencoder.encode(inputString)方法在GWT客户端不起作用(我的代码驻留在客户端模块中)导致错误'您是否忘记继承所需的模块?'
  2. URL.encodeQueryString(inputString)效果很好但是当我使用JUnit运行相关的测试用例时,我得到的只是unsatisfiedlinkederror
  3. 编码方法是否有其他选择,或者上述方法是否有解决方法?

3 个答案:

答案 0 :(得分:1)

第二种选择: GWT使用模块并需要编译,这与运行简单的JUnit测试不同。看一下http://www.gwtproject.org/doc/latest/DevGuideTesting.html,他们解释了如何设置JUnit测试。

答案 1 :(得分:0)

只需使用URL类及其方法:

不要忘记继承所需的模块<inherits name="com.google.gwt.http.HTTP"/>

答案 2 :(得分:0)

对于网址构建,我使用“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();

此代码将导致: https://www.mysite.com:8080/myServlet?username=GWT%20User&someAttribute=itsValue

相关问题