2014-06-25 36 views
0

下面的代碼片段:xssAPI不能在我的CQ5組件JSP來解決錯誤

<%@taglib prefix="cq" uri="http://www.day.com/taglibs/cq/1.0" %> 
<%@taglib prefix="sling" uri="http://sling.apache.org/taglibs/sling/1.0" %> 
<sling:defineObjects /> 
<cq:defineObjects /> 
<label class="form_label" for="send_to"><%=xssAPI.encodeForHTML(sendToLabel)%></label> 

連我也包括仍然global.jsp獲得編譯錯誤

回答

0

CQ5哪個版本您使用的?如果是CQ 5.4,則包含global.jsp時,xssAPI不可用。您可以使用XSSProtectionService.class來保護XSS。

可以從sling.getService()獲得XSSProtectionService,並且可以使用protectFromXSS()

final XSSProtectionService xss = sling.getService(XSSProtectionService.class); 
xss.protectFromXSS(sendToLabel); 
0

我認爲這個問題是由未知引起變量sendToLabel。使用propertiesValueMap獲得此屬性:

<%=xssAPI.encodeForHTML(properties.get("sendToLabel", String.class))%> 
+0

沒有Tomek,sendToLabel已經聲明String sendToLabel = propertiesfile.getProperty(「sendToLabel」);.我沒有在我的描述中包含整個代碼。我們正在從屬性文件中檢索此值 – user2930621

+0

您是否可以發佈整個代碼或製作組件的更簡單的版本,以免遭受同樣的問題?幷包含編譯錯誤體? –

相關問題