Confusion about JSP and HTML pages | Community
Skip to main content
LinearGradient
Level 6
October 16, 2015
Solved

Confusion about JSP and HTML pages

  • October 16, 2015
  • 3 replies
  • 1454 views

Hi,

I find myself confused every now and then regarding HTML pages, JSP pages, etc. in CQ5. I guess I have to re-read the Sling docs again.

But basically, at the moment, under our app folder (e.g. /apps/foo) we have a bunch of .html pages that are requested by our Angular JS app via AJAX.

I want to add some dynamic code to these pages (e.g. JSP scriptlets, etc.)

What is the proper way of doing this in CQ 5?

Thanks.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by PaulMcMahon

The proper way is generate the HTML files your angular app uses from a JSP. 

So what you would is create the following:

  • A template at say /apps/foo/templates/angular - this template points a resource type of /apps/foo/components/angular
  • You create a components at /apps/foo/components/angular and then a JSP are /apps/foo/components/angular/angular.jsp.
  • In angular.jsp you put you static HTML content along with whatever scriptlets you want. 
  • Then you create a CQ page at say /content/angular/en/myapp based on you template at /apps/foo/templates/angular
  • You point your angular app at /content/angular/en/myapp.html 

3 replies

PaulMcMahonAccepted solution
Level 8
October 16, 2015

The proper way is generate the HTML files your angular app uses from a JSP. 

So what you would is create the following:

  • A template at say /apps/foo/templates/angular - this template points a resource type of /apps/foo/components/angular
  • You create a components at /apps/foo/components/angular and then a JSP are /apps/foo/components/angular/angular.jsp.
  • In angular.jsp you put you static HTML content along with whatever scriptlets you want. 
  • Then you create a CQ page at say /content/angular/en/myapp based on you template at /apps/foo/templates/angular
  • You point your angular app at /content/angular/en/myapp.html 
October 16, 2015

Oratas has covered the basics.... Or you could think about moving to v6 so you can use HTML with Sightly and finally get rid of all that JSP nonsense.

GabrielWalt
Adobe Employee
Adobe Employee
October 16, 2015

I'd advise you to go with Sightly instead of JSP for any new project as it is designed to replace JSP. This will give you automatic proper HTML encoding and cross-site scripting protection built-in. It will also force some healthy separation of concerns, preventing the kind of code & markup mix you typically can end-up with in JSPs. Thus making the markup overall more readable.