Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

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

0 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