Domanda

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

È stato utile?

Soluzione

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

Altri suggerimenti

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

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top