0

I have this code:

<%@ include file="/WEB-INF/views/include.jsp" %>

<body>
    <div class=col1>
        <h1>Projects</h1>
        <p>Selecciona un proyecto de la lista</p>
        <h3>Projects</h3>
   <c:forEach items="${model.projects}" var="project">
      <a href="project_popup.htm" onclick=<% application.
                    setAttribute("project", project); %>>
        <c:out value="${project.getProject().getName()}"/><br></a>
      <c:out value="${project.getRol().getString()}"/><br>
      <c:out value="${project.getDateStart()}"/><br>
      <br><br>
    </c:forEach>

    </div>
</body>

line: <a href="project_popup.htm" onclick=<% application.setAttribute("project", project); %>>, fails because project cannot be resolved into a variable even if it's on the foreach loop...

does anyone knows how to access those variables?

thanks

1 Answer 1

2

If you have get/set methods established for each field on an object you simply use the field name.

  <c:out value="${project.project.name}"/><br></a>

I'm a little suspicious as to why a project would have a project field. Are you sure you didn't want:

  <c:out value="${project.name}"/><br></a>

This piece of code won't fly however:

<a href="project_popup.htm" onclick=<% application.
                    setAttribute("project", project); %>>

You cannot trigger some server side event using the onclick attribute of an a tag. The client cannot directly execute some code on the server, it needs to happen through a request. Usually, ajax and a servlet is used to handle this type of scenario, although you could also send a full request to the server.

Here is a simple example showing how to use servlets

Sign up to request clarification or add additional context in comments.

1 Comment

the project var within a project var is fine, i will rename it in order to be more clear, but that works fine... the problem with the other piece of code is the following: i want to print a list of the projects the user is working at, and the user will be able to click any of the tittles of these projects to access further details. i have another jsp for the project.jsp single display, but i don't know how to pass the proper project variable to it

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.