Reputation: 1389
I have a field helper jsp file which churns out code for various components. The field helper jsp returns a string which is used by another jsp, which shall be called foo. I need to have the scriplet tags in foo in order to call the URLEncoder encode method. Unfortunately, the field helper jsp is causing errors due to the <% %> in htmlString. Is there any way to escape the <% %> tags in a jsp?
Tech: struts 1.3 & jdk 1.7 excerpt of field helper jsp
<%
//do stuff here
htmlString.append("<TD> <A HREF=\"fileDownload.jsp?filename=<%=URLEncoder.encode("+example+")%>\" TARGET=\"_BLANK\"> "+foo+" </A></TD>");
return htmlString;%>
I have already tried the following escapes:
\<% %\n
<\% \%>
\<\% \%\>
Upvotes: 1
Views: 313
Reputation: 201419
There isn't any need to do so, you can call URLEncoder.encode(String)
directly. Something like
htmlString.append("<TD> <A HREF=\"fileDownload.jsp?filename="
+ URLEncoder.encode(example) + "\" TARGET=\"_BLANK\">"
+ foo + " </A></TD>");
Upvotes: 2