I have a link on my page, that when clicked calls a method with 2 arguments. One of these arguments may have special characters (ie ‘ or é etc.). I get page errors when I try to pass such variables, so I am trying to encode them before passing them. How can I call encodeURIComponent inline?
I am trying to do this:
<a title="${facet.toolTipDisplay}" onclick="submitFacet('Company', '${encodeURIComponent(facet.javaScriptVar)}')">
And I seem to be getting the error:
SEVERE: Servlet.service() for servlet jsp threw exception
org.apache.jasper.JasperException: /WEB-INF/pages/SearchForm.jsp(831,126) The function encodeURIComponent must be used with a prefix when a default namespace is not specified
DISCLAIMER: I am new to web stuff and only have access to the JSP page and not the java class where the facet.javaScriptVar is coming from.
I decided to go with just replacing the apostrophe with “\'” (escaped apostrophe). When my function is called the escaped apostrophe is replaced with the apostrophe like normal.
This is what it looks like within the HTML:
Then what it looks like when the submitFacet function is called: