Why we use double % in Java or JSP

111 Views Asked by At

When I checked a code yesterday, I've seen a line that was very strange for me.

There's a condition in JS code which is checking a string passed by parameter in this way "%%unsubscribe%%". Please check the below line for reference

if (link.attr("href").equalsIgnoreCase("%%unsubcriber%%"))

There's another reference in JSP page that is also very strange to me.

<a style="color: rgb(153, 153, 153); " href="%%unsubcriber%%">Unsubscribe</a> 

Please help me out, why we use double % in Java?.

3

There are 3 best solutions below

0
On

Looks like template placeholders. If you look elsewhere in the code, you're likely to find somewhere that the code is taking a string containing that HTML and doing a replace or replaceAll on it, converting %%unsubscriber%% to someone's name/username.

5
On

As I explained in your Quora (?) post, and you neglected to post here, that line appears in a <script> tag, e.g.,

<script>
    if (link.attr("href").equalsIgnoreCase("%%unsubcriber%%"))
</script>

Your code is using a templating system. The %% is meaningless to JSP and will render as-is. Your JavaScript code loads the template by referencing the <script> tag and fills it in with data provided by JavaScript, using whatever templating system you're using.

0
On

%%unsubcriber%% is a simple text marker in the text/html document generated from JSP. It could also be a part of custom HTML template. After the page is rendered, a custom HTML with values like that replaced with real values before writing the text/html to the response.