I have list string in java (get from DB) and I want use it in Javascript. Here is my code
<bean:define id="listHistory" name="myForm" property="info.listHistory" type="java.util.List"/>
<script>
var listHistory = [];
$( document ).ready(function() {
listHistory = convertData();
}
function convertData(){
let listData = [];
<% for ( int i=0;i< listHistory.size() ;i++ ) {%>
listData.push("<%=listHistory.get(i).toString()%>");
<% } %>
return listData;
}
</script>
It work if item in List java have normal character, but when String have " or ; or ', it will error.

How I can fix it?