How to pass as a parameter in a 'items' method of a forEach, a URL variable?

1

I am developing a project in Java, academic work. My doubt is in the following. I can display the items related to a logged in user, where the value (nick) is set in a session named login. See:

<jsp:useBean id="dao" class="dao.CestaDAO" />
<c:forEach var="item" items="${dao.findItens(login)}">
  ${item.nome}
</c:forEach>

Everything rolls perfectly. However, I'm having trouble when as an administrator, when I click on a link that passes a variable via URL (? ClientLogin = so-and-so). I can not get the value and play as parameter in findItems (). I must be making a silly mistake, Java is not the language I master. Thanks!

String cliente=request.getParameter("clienteLogin").toString();

<jsp:useBean id="dao" class="dao.CestaDAO" />
<c:forEach var="item" items="${dao.findItens(cliente)}">
  ${item.nome}
</c:forEach>
    
asked by anonymous 08.02.2017 / 19:56

1 answer

1

Well, I was able to resolve using sessionScope . This is the only way to set the attribute (client) and use it as a parameter in $ {dao.findItens (client)} .

         <c:choose>
            <c:when test="${sessionScope.login != null && sessionScope.login ne 'admin'}">
                <% pageContext.setAttribute("cliente", String.valueOf(session.getAttribute("login")), PageContext.SESSION_SCOPE);
                %>
            </c:when>

            <c:when test="${sessionScope.login == 'admin'}">

                <% pageContext.setAttribute("cliente", String.valueOf(request.getParameter("clienteLogin")), PageContext.SESSION_SCOPE);
                %>
            </c:when>
        </c:choose>

        <h1>Lista de  ${sessionScope.cliente}</h1>

        <jsp:useBean id="dao" class="dao.CestaDAO" />
        <ul>
            <c:forEach var="item" items="${dao.findItens(cliente)}">
                <li>${item.nome}</li>
            </c:forEach>
        </ul> 
    
09.02.2017 / 00:35