1

I cannot print the list of elements of my for in jsp.If I put the quotes instead of the single quote, it gives me other errors, if I put the variable without $, the blank page appears. It would take a link to the correct syntax of variables nested in methods called by variables with the $.

This code gives me these errors:

 <%@ page language="java" contentType="text/html; charset=UTF-8"
 pageEncoding="UTF-8" isELIgnored="false"%>

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

 <!DOCTYPE html>

 <html>
 <head>
 <meta charset="ISO-8859-1">
 <title>Lista parlamentari</title>
 <script src="<c:url value="/resources/js/jquery-1.11.1.min.js" />"></script>
 <script src="<c:url value="/resources/js/bootstrap.min.js" />"></script>
 </head>
 <body>    
 
 <h2>Lista dei parlamentari:</h2>
 <form method="POST" action="lista_parlamentari.jsp">
 <c:forEach items="${parlamentari}" var="parlamentare">
 <table>
 <tr>
 <td>Nome:</td>
 <td><c:out value="${parlamentare.getPk().getNome()}"/></td> <!-- se non funziona 
 prova con getPk().getNome() -->
 </tr>
 <tr>
 <td>Partito:</td>
 <td><c:out value="${parlamentare.getPk().getPartito()}"/></td> 
 </tr>
 <tr>
 <td>Circoscrizione:</td>




    <c:forEach items="${parlamentare.getPk().getCircoscrizione()}" 
var="CIRCOSCRIZIONE" varStatus="myIndex"> 
 
<td><c:out value="${CIRCOSCRIZIONE.getElement( '<c:out value='${circoscrizione}'/>', 
'<c:out value='${loop.index}'/>')}"/><br></td> 
        </c:forEach>
   </tr>
    <tr>   
   <td>Data di nascita:</td>
   <td><c:out value="${parlamentare.getData_nascita()}"/><br></td>
  </tr>
  <tr>
     <td>Luogo:</td>
   <td><c:out value="${parlamentare.getLuogo()}"/><br></td>
   </tr>
   <tr>
     <td>Titolo di studi:</td>
   <td><c:out value="${parlamentare.getTitolo_studi()}"/><br></td>
   </tr>
   <tr>
   <td>Mandati:</td>
   <c:forEach items="${parlamentare.getMandati()}" var="mandato" varStatus="myIndex">
       <table>
        <tr>
       <td>Mandato:</td> 
       <td><c:out value="${mandato.getElement('<c:out value='${mandato}'/>','<c:out 
  value='${myIndex.index}'/>')}" /> </td>
       </tr>
       </table>
       </c:forEach>
 </tr>
 
 <tr>
     <td>Commissioni:</td>
      <c:forEach items="${parlamentare.getCommissioni()}" var="commissione" 
 varStatus="myIndex">
       <table>
        <tr>
       <td>Commissione:</td> 
       <td><c:out value="${commissione.getElement('<c:out 
 value='${commissione}'/>','<c:out value='${myIndex.index}'/>')}"/></td>
       </tr>
       </table>
       </c:forEach>
   </tr>
  
   </table>
   </c:forEach>
 
     </form>
     
</body>
</html>

stacktrace:

    SEVERE: Servlet.service() for servlet [jsp] in context with path [/Parlamento] 
    threw exception [/lista_parlamentari.jsp (line: [38], column: [4]) 
    [${CIRCOSCRIZIONE.getElement( '<c:out value='${circoscrizione}'/>', '<c:out 
    value='${loop.index}'/>')}] contains invalid expression(s): 
    [jakarta.el.ELException: Failed to parse the expression 
    [${CIRCOSCRIZIONE.getElement( '<c:out value='${circoscrizione}'/>', '<c:out 
    value='${loop.index}'/>')}]]] with root cause
    org.apache.jasper.JasperException: /lista_parlamentari.jsp (line: [38], column: 
    [4]) [${CIRCOSCRIZIONE.getElement( '<c:out value='${circoscrizione}'/>', '<c:out 
    value='${loop.index}'/>')}] contains invalid expression(s): 
    [jakarta.el.ELException: Failed to parse the expression 
    [${CIRCOSCRIZIONE.getElement( '<c:out value='${circoscrizione}'/>', '<c:out 
    value='${loop.index}'/>')}]]

Lista_parlamentari.java

 public ModelAndView doPost()//(Parlamentare parlamentare) 
 {  
    ModelAndView mv= new ModelAndView();

    List<Parlamentare> parlamentari =parlamRepo.findAll();
    mv.addObject("parlamentari",parlamentari);
    mv.setViewName("lista_parlamentari.jsp");
    return mv;
 }

Update: I modified the code with the solutions I found at these links, but the page remains blank and I have no stacktrace from the server.Can anyone help me please? Thank you

Doubly nested EL variables?

https://docs.oracle.com/javaee/5/tutorial/doc/bnahq.html#bnaij

${requestScope['javax.servlet.forward.servlet_path']}

lista_parlamentari.jsp

<c:forEach items="${parlamentare.getPk().getCircoscrizione()}" 
 var="CIRCOSCRIZIONE" varStatus="myIndex"> 

<td><c:out 
value= 
"${CIRCOSCRIZIONE}.getElement(${requestScope['CIRCOSCRIZIONE']}, 
${requestScope['myIndex.index']})"/><br></td> 
    </c:forEach>

update: I changed the code like this, but it just prints the title, the page remains blank. I followed the directions at this link:

How to nest an EL expression in another EL expression

<c:forEach items="${parlamentare.getPk().getCircoscrizione()}" 
var="CIRCOSCRIZIONE2" varStatus="myIndex"> 
     <c:set var="circoscrizione" 
value= 
"circoscrizione.getElement(${CIRCOSCRIZIONE2},${myIndex.index})" 
 />
    ${requestScope[circoscrizione] }
      <c:out value="${circoscrizione}" />
      </c:forEach>

SOLUZIONE: <c:set var="circoscrizione" value="${CIRCOSCRIZIONE2.getElement(CIRCOSCRIZIONE2,myIndex.index)}"/>

0 Answers0