Search code examples
ajaxjspjstl

JSTL foreach and AJAX load() not working


My app.jsp file is this:

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <link rel="shortcut icon" type="image/x-icon" href="imgs/ano_white.png">
    <title>Home - Hackeet</title>
</head>
<body>
    <div class="container">
        <div class="mainCont"></div>
    </div>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
    <script src="js/register.js"></script>
    <script src="js/app.js"></script>
</body>
</html>

And my file call to AJAX is this:

$('.mainCont').load('register');

My JSP file is this:

<input list="teams" name="team" placeholder="Team Name">
<datalist id ="teams">
   <c:forEach items="${teams}" var="team">
      <option value="${team}"></option>
   </c:forEach>
</datalist>

And the exit in chrome dev tools:

<c:foreach items="[Stratagee, The Best Team (TBT), Alex_peroGriego_TEAM, Excella]" var="team">
   <option value=""></option>
</c:foreach>

As you see the elements are introduced correctly, but foreach is not working.


Solution

  • SOLVED, I include this:

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

    In register.jsp file and all works