如何在JSP中列印Java表示式的結果?
<c:out>標籤顯示錶達式的結果。這與<%= %>的工作方式幾乎相同。區別在於<c:out>標籤允許您使用更簡單的"."表示法來訪問屬性。例如,要訪問customer.address.street,請使用標籤 <c:out value = "customer.address.street"/>。
<c:out>標籤可以自動轉義XML標籤,因此它們不會被評估為實際標籤。
屬性
<c:out>標籤具有以下屬性:
屬性 | 描述 | 必填 | 預設值 |
---|---|---|---|
值 | 要輸出的資訊 | 是 | 無 |
default | 要輸出的備用資訊 | 否 | body |
escapeXml | 如果標籤應轉義特殊的XML字元,則為True | 否 | true |
示例
<%@ taglib uri = "http://java.sun.com/jsp/jstl/core" prefix = "c" %> <html> <head> <title> <c:out> Tag Example</title> </head> <body> <c:out value = "${'<tag> , &'}"/> </body> </html>
以上程式碼將生成以下結果:
<tag> , &
廣告