如何编码和解码字符串以便在查询字符串中使用?

时间:2014-08-27 18:59:22

标签: java jsf url-encoding

如何在jsf中表示查询字符串?

我有一个类似于下面的查询字符串。

  

... /面/ WPages /导航/ Catalog.xhtml STOREID = 1&安培; CATEGORYID = 1005&安培; drilldownproperty1 = drilldownpropertyval1&安培; drilldownproperty2 = drilldownpropertyval2&安培; drilldownproperty3 = drilldownpropertyval3&安培; ...

我想代表参数

drilldownproperty1=drilldownpropertyval1&drilldownproperty2=drilldownpropertyval2&drilldownproperty3=drilldownpropertyval3 ...

有类似的东西:

drilldownproperty=drilldownpropertyvals

其中drilldownpropertyvals代表drilldownproperty1=drilldownpropertyval1&drilldownproperty2=drilldownpropertyval2&drilldownproperty3=drilldownpropertyval3

如何在我的managebean上执行url重定向之前和之后对字符串进行编码和解码?

1 个答案:

答案 0 :(得分:1)

java.net.URLEncoderjava.net.URLDecoder for。

String url = "some.xhtml?drilldownproperty=" + URLEncoder.encode(drilldownpropertyvals, "UTF-8");

然后在另一边

String drilldownpropertyvals = URLDecoder.decode(drilldownproperty, "UTF-8");