2012-08-30 50 views
0

考慮這種情況:套裝屬性之前JSP

<!-- 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%> 

如果我執行main.jsp我得到這樣的結果:

0 1 2 3 4 5 6 7 8 9 

這就是我想要的。

但問題是:

顯示順序將永遠是這樣嗎? 我應該爲請求提供同步嗎?

感謝

回答

2

顯示順序將始終是相同的,

你把它要求這是每個請求的新實例,因此沒有必要同步

1

synchronization的幾乎總是不在開發Java EE應用程序時需要。所以如果你有疑問,不要使用它。