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

Was it helpful?

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

OTHER TIPS

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top