When I place the following jQuery code in JSP:
<script>
$(document).bind("ready",function(){
var recordPerPages=3;
var currentPage=1;
var trs=$("table tr");
alert(trs);
function create(pageNo){
$("table").empty();
var endRec=pageNo*recordPerPages;
var stRec=endRec-recordPerPages;
trs.each(function(indx){
if((indx+1)>=stRec && indx<endRec){
$("table").append($(this))
}
})
}
create(currentPage)
$("#prev").bind("click",function(){
currentPage=currentPage-1
create(currentPage)
})
$("#next").bind("click",function(){
currentPage=currentPage+1
create(currentPage)
})
})
</script>
Then I get the following error:
editListContributions.jsp:38:29: Illegal token.
if((indx+1)>= stRec && indx < endRec){
^
How is this caused and how can I solve it?
That can happen if you’re actually using JSPX instead of JSP. JSPX is XML based. All special characters in XML such as
<,&and>(which represent respectively the start of a XML element, the start of a XML entity and the end of a XML element) needs to be escaped as<,&and>.An alternative to this unreadable mess is to put the entire script in a
CDATAblock.Much better is however to put JS code in its own
.jsfile which you include by<script src>.See also: