Set attribute before include jsp

1.5k Views Asked by At

consider this situation:

<!-- main.jsp -->
<% for (int i = 0; i < 10; i++) { %>
    <% request.setAttribute("i", new Integer(i)); %>
    <jsp:include page="template.jsp" />
    <% request.removeAttribute("i"); %>
<% } %>

<!-- template.jsp -->
<jsp:useBean id="i" scope="request" type="java.lang.Integer" />
<%=i%>

If I execute main.jsp I get this result:

0 1 2 3 4 5 6 7 8 9

that's what I want.

But the question is:

The display order will always be this? Should I put a synchronization for the request?

Thanks

2

There are 2 best solutions below

0
On BEST ANSWER

Yes Display order will always be the same,

You are putting it to request which is new instance per request so no need of synchronization

0
On

synchronization is almost always not needed when developing Java EE applications. So if you are in doubt, don't use it.