json - AEM 将 html 信息注释插入 json

标签 json aem

我有以下jsp

<%
    JSONObject jsonResult = new JSONObject();
    response.setContentType("application/json");
    String parentNodePath = slingRequest.getRequestPathInfo().getResourcePath();
    String url = getServerBaseUrl(sling) + parentNodePath.split("/jcr:content")[0] + ".html?cid=twitter";
    UrlShortener urlShortener = sling.getService(UrlShortener.class);
    String shortUrl = urlShortener.shorten(url);
    String encShortUrl = URLEncoder.encode(shortUrl);
    jsonResult.put("url", url);
    jsonResult.put("shortUrl", shortUrl);
    jsonResult.put("encShortUrl", encShortUrl);
%>
<%=jsonResult.toString()%>

当我在浏览器中输入以下地址时执行 http://servername:port/path/to/page.urlshortener.html.jsp

如您所见,我有“application/json”内容类型。结果必须只包含json信息,但有html注释:

{
    "url":"http://servername/content/app/test/test1/naps1.html?cid=twitter",
    "shortUrl":"http://servername/1E4sZYJ",
    "encShortUrl":"http%3A%2F%2Fservername%2F1E4sZYJ"
}
<!--
    cq{
        "decorated":false,
        "type":"app/components/page/newsarticlepage",
        "path":"/content/app/test/test1/naps1/jcr:content",
        "selectors":"urlshortener",
        "servlet": "Script/apps/app/components/page/contentpage/urlshortener.html.jsp","totalTime":276,"selfTime":276
    }
-->

我还看到,这个注释插入在每个组件之后,或者在任何页面中执行jsp。 如何关闭此评论的插入?

最佳答案

评论<!-- cq{ ... } -->为创作界面添加了。它们不包含在禁用 wcmmode 的发布实例中。您可以通过添加 wcmmode=disabled 来看到这一点作为查询参数添加到您的网址末尾。此外,您还必须删除 cf#editor.html从网址。

关于json - AEM 将 html 信息注释插入 json,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29561075/

相关文章:

jquery - 通过 JQuery 和 JSON 设置 ASP LinkBut​​ton 控件的文本

javascript - 基于组件的客户端库 AEM

java - 当从某个组件创建页面时,我可以以编程方式创建额外的页面吗?

aem - JavaScript 使用 API 与 Java 使用 API

osgi - FOP/AEM : Deserialization not allowed for class org. apache.fop.fonts.FontCache

javascript - 将 highchart 中的 x y 点绘制为 [[x 点列表],[y 点列表]]

java - 将 JSON 反序列化为未知类型的集合

json - 如何在 VB.NET Newtonsoft 中解析 Json 列表

json - Pandas 将字符串类型的 JSON 值转换为 INT

aem - 直接去除装饰标签 aem