0

How can I change to correct below code?

<%!
    public String renderComment(String comment) {
        return comment.replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll("\n", "<br />");
    }
%>

<c:forEach var="answer" items="${answerList}" varStatus="status">
    <%=renderComment(${answer.cn})%> <!-- This is wrong. -->
    <%=renderComment(answer.cn)%> <!-- This is wrong.-->
    ${renderComment(answer.cn)} <!-- This is wrong, too! How can I do? -->
</c:forEach>
Jaime
  • 2,148
  • 1
  • 16
  • 19
  • It would have to be something like <%=renderComment((String)(pageContext.getAttribute("answer").cn))%> But the field cn might be a problem. What does the getter and setter signatures look like? – rickz Dec 01 '15 at 02:55
  • Or maybe something like <%=renderComment((Answer)(pageContext.getAttribute("answer")).cn)%> – rickz Dec 01 '15 at 03:02
  • @rickz This codes does not work. – Jaime Dec 01 '15 at 03:14
  • What type of objects are in answerList ? – rickz Dec 01 '15 at 03:30
  • The type of answerList is List>. I did trye (Map)(pageContext.getAttribute("answer")).cn – Jaime Dec 01 '15 at 04:43
  • For testing, did you try to display something using just El with no JSTL? What does ${answerList[0]} print? – rickz Dec 01 '15 at 05:22
  • only print value ${answer.cn}. It is work well. but I want remove HTML tags and line feed replace to
    tags
    – Jaime Dec 01 '15 at 05:43
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/96632/discussion-between--and-rickz). – Jaime Dec 01 '15 at 05:44

1 Answers1

0

I guess, there is no way.
However, I found a another way.

How to call a static method in JSP/EL?

Probably, this way is best.

Community
  • 1
  • 1
Jaime
  • 2,148
  • 1
  • 16
  • 19