0

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?

secretformula
  • 6,414
  • 3
  • 33
  • 56
banduk
  • 107
  • 1
  • 7
  • `#` is the fragment identifier. If it's part of a parameter in the query string, you must url encode the query string first. If you just want to get the fragment, I'm sure whatever wrapper you are using can do it in a similar fashion as getting the query string – Explosion Pills Aug 23 '11 at 18:33

2 Answers2

5

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.

Community
  • 1
  • 1
Ryan Stewart
  • 126,015
  • 21
  • 180
  • 199
  • Right, works perfectly! **URLEncode** and **URLDecode**. I didn't want to use it because the part of the system that generates it is supposed to be the most general as possible and not all the data will be url. But there's no problem to encode all data. Thanks – banduk Aug 24 '11 at 11:15
1

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

JB Nizet
  • 678,734
  • 91
  • 1,224
  • 1,255