2011-12-12 30 views
3

我一個屬性設置到會話中使用時,其必須轉義:session.getAttribute()被引用了「值

HttpSession session = request.getSession(); 
System.out.println(al); 
session.setAttribute("arraylist",al); 

的人是Employee對象的列表還可以我看到的System.out在控制檯打印 但是,當我想從列表JSP爲:

<% 
List<Employee> employees = (List<Employee>)session.getAttribute("arraylist"); 

for(int i=0;i<employees.size();i++){ 
    Employee emp = employees.get(i); 
    out.println(emp.getFirstName()); 
    out.println(emp.getLastName()); 
    out.println(emp.getAddress()); 
    out.println(emp.getContact()); 
    out.println(emp.getEmail()); 
} 
%> 

我收到錯誤:

Attribute value (ArrayList<Employee>)session.getAttribute("arraylist") is quoted with " which must be escaped when used within the value 

我正在使用Tomcat 6.0.33。任何信息都會非常有幫助。

謝謝。

+0

你確定沒有從JSP中的任何其他位置獲取該屬性嗎?它是否僅在您發佈的腳本中? – adarshr

+0

看看相關的threds - http://www.coderanch.com/t/520610/vc/Help-Code-running-file-IDE和http://www.coderanch.com/t/455557/JSP/java /差錯時,會話的getAttribute – adatapost

回答

3

使用JSTL forEach來迭代集合。

<c:forEach var="emp" items="${arraylist}"> 
    <c:out value="{emp.firstName}"/> 
</c:forEach> 
5

也許

-Dorg.apache.jasper.compiler.Parser.STRICT_QUOTE_ESCAPING=false 

幫助。檢查更嚴格的報價規則。

相關問題