可參考jsp的API隱式對象..
這部分數據其實被保存在page域中,但jsp中如果使用java代碼需要在特定的標籤中<%%>,在這個標籤中可使用的只有pageContext對象,所以可以這樣
比如:
//java後臺代碼 List<String> list=new ArrayList<String>(); list.add("a"); request.setAttribute("list",list);
<%--前臺代碼--%> <c:forEach items="${list}" var="s"> <c:out value='${s}'/> <%--如果要使用這個遍歷結果--%> <% String str=(String)pageContext.findAttribute("s"); if(str=="a"){ ... } %> </c:forEach>
可以直接用 :pageContext.findAttribute("s"); 取值,強轉成目標對象類型使用就行!