2014-08-27 164 views
0

如何在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

我怎麼編碼前和執行中的URL我managebean重定向解碼後的字符串?

回答

1

這裏有java.net.URLEncoderjava.net.URLDecoder

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

然後在另一側上

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

謝謝,這是一個簡單的解決方案。 – fs2050 2014-08-27 20:40:41