简体   繁体   中英

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. w3schools has encoding tables so you can look up the values yourself, too.

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:

<c:url value="/path/to/myServlet">
    <c:param name="param1" value="#paramValue"/>
</c:url>

If you're using straight Java, use URLEncoder.encode() .

If the URL is static, use %23paramValue instead of #paramValue

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM