How to URL encode a URL in JSP / JSTL?

Since you are using JSP, I would stick to JSTL and not use scriptlets. You could use the JSTL tag <c:url /> in combination with <c:param />:

<c:url value="/yourClient" var="url">
  <c:param name="yourParamName" value="http://google.com/index.html" />
</c:url>

<a href="https://stackoverflow.com/questions/15923062/${url}">Link to your client</a>

This will result in:

<a href="https://stackoverflow.com/yourClient?yourParamName=http%3a%2f%2fgoogle.com%2findex.html">Link to your client</a>

Leave a Comment