I am trying to use the encodeURL
method in a jsp to encode a URL with \"%\" symbol.
response.encodeURL(/page1/page2/view.jsp?name=Population of 91% in
The HttpServletResponse#encodeURL() method has actually a misleading name. Read the javadoc to learn what it really does (appending the jsessionid
if necessary). See also In the context of Java Servlet what is the difference between URL Rewriting and Forwarding? to learn about ambiguties in JSP/Servlet world.
In the servlet side, you need URLEncoder#encode() instead:
String url = "/page1/page2/view.jsp?name=" + URLEncoder.encode("Population of 91% in this place", "UTF-8");
// ...
In the JSP side, however, you need the JSTL
tag instead (avoid Java code in JSP!):
<%@ page pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
...
link