我有一个字段帮助器 jsp 文件,它为各种组件生成代码。字段助手 jsp 返回一个字符串,该字符串由另一个 jsp 使用,该 jsp 称为 foo。我需要在 foo 中包含 scriplet 标签才能调用 URLEncoder 编码方法。不幸的是,字段助手 jsp 由于 htmlString 中的 <% %> 而导致错误。有什么方法可以转义 jsp 中的 <% %> 标记吗?
技术:struts 1.3 & jdk 1.7 字段助手 jsp 摘录
<%
//do stuff here
htmlString.append("<TD> <A HREF=\"fileDownload.jsp?filename=<%=URLEncoder.encode("+example+")%>\" TARGET=\"_BLANK\"> "+foo+" </A></TD>");
return htmlString;%>
我已经尝试过以下转义:
\<% %\n
<\% \%>
\<\% \%\>
最佳答案
没有必要这样做,直接调用URLEncoder.encode(String)
即可。类似的东西
htmlString.append("<TD> <A HREF=\"fileDownload.jsp?filename="
+ URLEncoder.encode(example) + "\" TARGET=\"_BLANK\">"
+ foo + " </A></TD>");
关于java - 在jsp中转义<%%>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36243170/