Question

I have a page that contains dynamic content:

/content/foo/bar/baz.jsp

But I want it to be accessible with the .html extension.

What's proper way to do this?

Was it helpful?

Solution

You are confusing some concepts in Apache Sling.

On Sling you have two important directories /apps and /content. In /apps you should put all your JSPs, in /content, as the name suggest, you only put content. Content being resources and their properties.

Nodes in /content have a property sling:resourceType. When a node from /content is requested, Sling looks for the resourceType of that node and invokes a JSP in the matching directory under /apps (and /libs if not found).

So, you must put your JSP under /apps/yourapp/foo/bar/bar.jsp (or with the file named 'bar.html.jsp', if you want to be explicit).

Then create a node /content/page with a prop sling:resourceType="yourapp/foo/bar". When requesting /content/page.html, bar.jsp will be invoked.

The process that Sling chooses to select which JSP invoke at each request is a bit complicated at first, but it follows simple conventions regarding the name of the JSP. Check their documentation regarding URL to script resolution.

Check the Discover Sling in 15 minutes tutorial and the rest of their docs. They are pretty simple.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top