逃避&在URL中 [英] Escaping & in a URL

查看:117
本文介绍了逃避&在URL中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用jsps,在我的网址中,我有一个变量值,例如L& T。现在,当我尝试使用 request.getParameter 检索它的值时,我只得到L。它承认&作为分隔符,因此不会被视为整个字符串。

I am using jsps and in my url I have a value for a variable like say "L & T". Now when I try to retrieve the value for it by using request.getParameter I get only "L". It recognizes "&" as a separator and thus it is not getting considered as a whole string.

如何解决此问题?

推荐答案

java.net.URLEncoder.encode("L & T", "utf8")

这会输出URL编码,这可以作为GET参数:

this outputs the URL-encoded, which is fine as a GET parameter:

L+%26+T

这篇关于逃避&在URL中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆