0

I have the following code (jsp)

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>



 <script type="text/javascript">
      $(document).ready(function() { 

         <c:forEach items="${messages}" var="msg"  varStatus="i">

            alert("${msg.description}");

         </c:forEach>
      });

</script>

Ans messages is an Arraylist which passed into this JSP from a controller.

    model.addAttribute("messages", messages);

    return "the_above_jsp";

This was working fine until the description value hold the following string value.

New task assigned from project Hip Tensile Strength Analysis : Data Management/Analysis Task due date is 20140408

When description has this value it will show the error Uncaught SyntaxError: Unexpected token ILLEGAL

Why is that ?

prime
  • 14,464
  • 14
  • 99
  • 131

1 Answers1

0

I solved the issue by removing the newline characters from the string description when I set the attribute and pass the jsp.

    for(int i=0;i<messages.size();++i){
        messages.get(i).setDescription(messages.get(i).getDescription().replaceAll("\n", ""));          
    }


    model.addAttribute("messages", messages);

    return "the_above_jsp";

But I have no Idea how it worked. May be the illegal character was the newLine character. Or there may be a better explanation. Please modify this or add a new answer though I solved this in a wild guess.

prime
  • 14,464
  • 14
  • 99
  • 131
  • There is a very detailed answer in the possible duplicate link I posted in the comments to the original question. – avgvstvs Apr 04 '14 at 21:24