-1

Hi i have a hyperlink from hyperlink i am calling a servlet and also sending a parameter with request but when '%' appended with text then shows null value.

Code Of Jsp

 <h1><a href="test11?val=100%">click</a></h1>

Code of servlet

 String s=request.getParameter("val");
   out.print("this is a text"+s);

for <h1><a href="test11?val=100">click</a></h1> it works fine but when i add '%' it print null.

user3660263
  • 135
  • 1
  • 1
  • 13

2 Answers2

5

In order to get the % from an URL you should use it's URLEncoded version which is %25. So you will end with <h1><a href="test11?val=100%25">click</a></h1>

% in an URL is not just a character, is the the main character for the percent-encoding used in URLEncoding. Other special characters for URLs are ?, & and =

Please try to always encode your URLs, in java please check this link:Java URL encoding of query string parameters in order to do so.

Community
  • 1
  • 1
Garis M Suero
  • 7,974
  • 7
  • 45
  • 68
2

Since you are using JSP then try with JSTL to encode the URL.

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<c:url value="/test11" var="url">
    <c:param name="val" value="100%" />
</c:url>

<a href="${url }">click</a>

Read more about JSP Standard Tag Library

Braj
  • 46,415
  • 5
  • 60
  • 76