Set attribute before include jsp
-
29-06-2021 - |
Pregunta
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
Solución
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
Otros consejos
synchronization
is almost always not needed when developing Java EE applications. So if you are in doubt, don't use it.
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow