Question

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

Était-ce utile?

La solution

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

Autres conseils

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

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top