Java URLEncoding / Decoding URL Spaces with dashes [closed]

痴心易碎 提交于 2020-01-06 19:43:09

问题


I'm looking to encode filter parameters within a URL. I'd like a readable URL so I'd like to replace spaces with underscores.

Example aston martin encoded to aston_martin and not aston$0020martin. I would then need to be able to decode the URL back to aston martin.

My only concern is with search parameters naturally containing underscores. I'm not sure what you would do in this particular use case.

I'm a tapestry5 user, so I do have the option to override the URLEcoder, or could use the java URLEncoder. I just haven't figured out how to get it to encode things the way I'd like them.

Any help would be appreciated.


回答1:


You are confusing URL-encoding with java.net.URLEncoder. Not surprising, and not your fault. Despite its name, the latter process is for URL argument names and values, and the same in POST data. It is only the former that turns space into %20. The latter turns it into '+', which is (a) the correct thing to do for your filter parameters, (b) reversible, and (c) not as offensive as %20. Don't know where you got $0020 from.



来源:https://stackoverflow.com/questions/12944672/java-urlencoding-decoding-url-spaces-with-dashes

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!