Expand my Community achievements bar.

SOLVED

AEM inserts html info comment into json

Avatar

Level 3

I have the following 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()%>

 

It executed when I type in browser the following adresshttp://servername:port/path/to/page.urlshortener.html.jsp

As you see i have "application/json" contentType. Result must contain only json information, but there is html comment:

{ "url":"http://servername/content/betcom/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}-->

Also i saw, this comments inserted after every component, or executed jsp in any page. How to turn off insertion of this comment?

1 Accepted Solution

Avatar

Correct answer by
Level 3

There is no typo. I found two solutions

The first one is to replace http://servername:port/path/to/page.urlshortener.html with http://servername:port/path/to/page/jcr:content.urlshortener.html,

another one is to use additional parameter wcmmode=disabled

View solution in original post

3 Replies

Avatar

Employee Advisor

Hi,

is the ".jsp" extension on your URL a typo? It shouldn't be there, just use "http://servername:port/path/to/page.urlshortener.html". Or even better ""http://servername:port/path/to/page.urlshortener.json" and make sure, that you put your JSP code in a JSP called "urlshortener.json.jsp".

kind regards,
Jörg

Avatar

Correct answer by
Level 3

There is no typo. I found two solutions

The first one is to replace http://servername:port/path/to/page.urlshortener.html with http://servername:port/path/to/page/jcr:content.urlshortener.html,

another one is to use additional parameter wcmmode=disabled

Avatar

Employee Advisor

Hi

Yaraslau Dzenisiuk wrote...

There is no typo. I found two solutions

The first one is to replace http://servername:port/path/to/page.urlshortener.html with http://servername:port/path/to/page/jcr:content.urlshortener.html,

another one is to use additional parameter wcmmode=disabled

 

I would prefer the first one, as it creates static URLs, which is important in the publish usecase.

kind regards,
Jörg