2

I'm working on a Java web application and i want my JSP files to comunicate with my Servlets which comunicate with the database.

What is the best way to pass entities i have created from a Servlet to a JSP page?

1 Answer 1

5

The standard way to send information from a Servlet to a JSP is to put it in "request scope" using code like this:

List listOfUsers = myDAO.getUsers();    
request.setAttribute("users", listOfUsers);

In your JSP, you would retrieve the users object with something like:

<c:forEach var="user" items="users">
User: <c:out value="${user}"/>
</c:forEach>
Sign up to request clarification or add additional context in comments.

1 Comment

Hi , I have similar issue. I get a null when i try to do the above.

Your Answer

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