0

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?

TheFooProgrammer
  • 2,439
  • 5
  • 28
  • 43

1 Answers1

4

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.

anotherdave
  • 6,656
  • 4
  • 34
  • 65
santiagozky
  • 2,519
  • 22
  • 31
  • 2
    Note that /apps and /content are not fixed in any way, but it's correct that by default Sling looks for rendering scripts under /apps and /libs. Setting a sling:resourceType property on a node under /apps will also work (but let's not confuse things ;-) The key concept here is that as opposed to other Web frameworks Sling doesn't serve scripts, it serves content resources that are rendered via scripts or servlets. – Bertrand Delacretaz Mar 14 '14 at 09:06