0

Have .jsp file under /components

path looks like:
http://localhost:4502/apps/project-name/components/my-component/one.jsp

Is it possible get HTML content of this one.jsp by url without creating content node?

something like:

http://localhost:4502/apps/project-name/components/my-component/one.HTML

the .html content is needed for further rendering.

3
  • 3
    IIUC "the .html content is needed for further rendering" means that the HTML that your JSP is generating is meant to be included in another page. In this case you're better off using a <cq:include> JSP tag which includes the rendering of a resource. That would target a Sling resource (content or other node) of course. You can also include JSP's in other JSP's as usual using @include. Nov 12, 2013 at 9:17
  • Hi Bertrand, I see your point. One more clarification to be more detailed: this .html should be invoked on click on link (like <a href="this.html"/>)I mean that it would be reference to html content of jsp within other jsp page.
    – sergionni
    Nov 12, 2013 at 10:03
  • 1
    Ok so for this the recommended way is really to create a content node, if only to make sure access control is handled properly. You don't want your users to read JSPs in general, so putting the actual content somewhere else than under /apps is the recommended way. Nov 12, 2013 at 15:47

3 Answers 3

1

As far as i know, you cannot get the html content from the JSP directly by providing the path to the jsp file. It displays the content in the JSP as is without compiling.

One possible way is to create an nt:unstructured node with the sling:resourceType property set to the path of the jsp (something like below)

test: {
    sling:resourceType: "/apps/geometrixx/components/title/one.jsp",
    jcr:primaryType: "nt:unstructured"
}

And you can provide the path to the test node to get the html rendered by the jsp.

/apps/geometrixx/components/title/test
5
  • hi, thank you for answer, such approach causes error for me: Guice injector name not available.
    – sergionni
    Nov 12, 2013 at 9:11
  • @sergionni Are you using Slice framework ? The above example works in my server(doesnt have slice). Could you provide more information regarding the error so that we can figure it out?
    – rakhi4110
    Nov 12, 2013 at 9:31
  • yes, Sling. the error looks like: Caused by: java.lang.IllegalStateException: Guice injector name not available at com.cognifide.slice.api.tag.SliceTagUtils.getFromCurrentPath(SliceTagUtils.java:73) ...
    – sergionni
    Nov 12, 2013 at 9:38
  • looks like appName parameter from method SliceTagUtils.getFromCurrentPath is blank.What does this param mean?
    – sergionni
    Nov 12, 2013 at 9:40
  • @sergionni please check this link cognifide.atlassian.net/wiki/pages/…. They are trying to get the appName property specified in the <slice:lookup>, and if not specified, it checks for the "injectorName" property in the resource.
    – rakhi4110
    Nov 12, 2013 at 9:50
0

Your question is a bit vague but as far as i get it, you want to retrieve the html for the whole page which can be done by reading the input stream from a URL using java.net.URL utility.

May be you can also place an iframe inside your other jsp to get the contents.

4
  • i just want express .jsp as pure .html without creating node under content hierarchy, in order to acces this .jsp like: /one.html or some other similar way
    – sergionni
    Nov 11, 2013 at 18:10
  • No backend, just get html content by url, the question, is what url should be used. Thank you for assistance.
    – sergionni
    Nov 11, 2013 at 18:16
  • As i said you can use the URL utility for reading the contents of jsp as is.Here is a link for the same. The url you will supply in this can come from Externalizer. Refer Api methods of Externalizer publishLink //authorLink // absoluteLink. Externalizer can be used to configure links for various environments. Nov 11, 2013 at 18:23
  • i mean, can I get .html view like: /http://localhost:4502/apps/project-name/components/my-component/one.jsp/jcr:content/jcr:data or somethig other way?
    – sergionni
    Nov 11, 2013 at 18:42
0

You could always use a traditional .html file instead of a .jsp, but (perhaps obviously) you will lose all the server side capabilities afforded by JSP.

It is also worth noting that anonymous access is typically denied to /apps for security reasons, so this .html file would not be reachable on a publish instance with OOTB permissions.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.