How can I get request parameter value if value is hash symbol (#)

java, jsp

Solution

You cannot send a `#` with query string like that. It won't be a part of query string.

Quoting RFC - Section 3.4:

The query component is indicated by the first question mark ("?") character and terminated by a number sign ("#") character or by the end of the URI.

You need to encode the parameters in query string, before sending request. For e.g., In a `JSP` page, you can use `<c:url>` JSTL tag:

<c:url value="/MyApp/browse/alphabetical/result" var="url">
  <c:param name="startsWith" value="#" />
  <!-- Rest of the parameters -->
</c:url>

Problem

I have the following request url: ``` localhost:8080/MyApp/browse/alphabetical/result?startsWith=#&page=1&size=10&sort=title&order=asc ``` Notice the request parameter `"startsWith=#"`. I am unable to get `"#"` as the value of the `'startsWith'` request parameter. Instead, I get an empty string ("") as the value of the `'startsWith'` request parameter. Is there any possible way to get `"#"` as the value of the request parameter? THIS DOES NOT WORK: `${param.startsWith eq '#'}` THIS WORKS: `${param.startsWith eq ''}` If there is no way to handle this, I will have to resort to using `startsWith=0 ... startsWith=9` instead of `startsWith=#`, which I really don't want

Original source