[英]Get parameter with the character '#' from a query string on java
I am trying to get a request string that has the character #
and my parameter is got only until the #
. 我正在尝试获取具有字符
#
的请求字符串,并且仅在#
之前获取我的参数。 But the thing is that I need to have this character, can't remove it. 但问题是我需要拥有这个角色,无法将其删除。
Any idea? 任何想法?
Encode the # if it has to be there. 如果必须将# 编码 ,请对其进行编码 。 A literal # indicates a fragment id and can't be used in a URI for any other purpose.
文字#表示片段ID ,不能在URI中用于任何其他目的。 w3schools has encoding tables so you can look up the values yourself, too.
w3schools具有编码表,因此您也可以自己查找值。
You need to encode the parameter value correctly. 您需要正确编码参数值。
If the URL is generated by a JSP, make sure to use the JSTL c:url
tag: 如果URL是由JSP生成的,请确保使用JSTL
c:url
标记:
<c:url value="/path/to/myServlet">
<c:param name="param1" value="#paramValue"/>
</c:url>
If you're using straight Java, use URLEncoder.encode()
. 如果您使用的是
URLEncoder.encode()
Java,请使用URLEncoder.encode()
。
If the URL is static, use %23paramValue
instead of #paramValue
如果URL是静态的,请使用
%23paramValue
而不是#paramValue
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.