5

I've a DCP that renders a JSP statement <% out.println("Hello"); %>. I'm trying to execute the JSP statement by using the CD API on a static JSP page. I've tried all possible scenarios - making the DCP a REL and publishing it to the broker and making it a JSP and publishing it to the file system, but I'm not able to have the JSP statement executed.

Here's what I've tried so far:

  1. Made the DCP a JSP and configured the cd_storage_conf.xml to publish DCPs to the file system. The DCP goes to the file system as a JSP and I used the ComponentPresentationAssembler to execute the JSP statement. All I see on the page is the JSP statement rendered as-is. The static JSP page looks like this:
JSPPage dcdPage = new JSPPage(pageContext, "tcm:17-28489-64");
ComponentPresentationAssembler cpAssembler = new  ComponentPresentationAssembler(dcdPage);
out.println(cpAssembler.getContent(20154,1029));
  1. Made the DCP a REL and configured the cd_storage_conf.xml to publish DCPs to the broker database. The DCP goes to the broker and I used the ComponentPresentationAssembler to execute the JSP statement, but still no luck. The page has the JSP statement rendered as-is.

I've looked into TREX, but couldn't find anything that helps resolve this issue. There was something similar Java code in DCP not exectued, but that too doesn't seem to have a solution. Any help would be greatly appreciated.

Update 1:

Using the code above doesn't seem to call the JSPProcessor. I believe it just gets the file from the location and displays it. The log shows no errors in this case.

2016-12-05 21:41:06,796 DEBUG FSComponentPresentationDAO - Retrieving default data location for publication: 17 2016-12-05 21:41:06,796 DEBUG FSComponentPresentationDAO - Looking for location for component presentation type: JSP 2016-12-05 21:41:06,797 DEBUG FSComponentPresentationDAO - FSComponentPresentationDAO.getFile(): Location found: C:\test\WebContent\dcp 2016-12-05 21:41:06,799 DEBUG ComponentPresentationAssembler - ComponentPresentation.getContent(componentId=19894;templateId=1029) found: com.tridion.storage.mapper.componentpresentations.JSPComponentPresentationImpl@14f2b1ba

However, if I use tridion tags, the JSPProcessor is called and there's an error thrown. Nothing gets rendered on the page.

<tridion:ComponentPresentation templateURI="tcm:17-1029-32" pageURI="tcm:17-28489-64" componentURI="tcm:17-20154"></tridion:ComponentPresentation>

The log shows an error here.

2016-12-05 21:50:03,298 DEBUG ComponentPresentationAssembler - ComponentPresentation.getContent(...) running JSP ComponentPresentation 2016-12-05 21:50:03,298 DEBUG JSPProcessor - JSPProcessor.run(...) absolutePath of cp: C:\test\WebContent\dcp\dcp1029_19894.jsp 2016-12-05 21:50:03,298 DEBUG JSPProcessor - JSPProcessor.run(...) documentroot C:.metadata.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\test\ 2016-12-05 21:50:03,298 ERROR JSPProcessor - JSPProcessor.run(...) The JSP ComponentPresentation is not located in the documentroot of your website; C:.metadata.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\test;C:\test\WebContent\dcp\dcp1029_19894.jsp

My question now is why does the JSPProcessor looking in the web root? Shouldn't it be looking in the sub-directory that's defined in the cd_storage_conf.xml?

1
  • 1
    Putting the DCP on the FS is the right path. Your issue is because you're printing the DCP as a string in your code. You need to not render the DCP as a string, but run it as an include instead. Check if the API has a method or property to get your the FS path to the item. Commented Dec 4, 2016 at 18:00

1 Answer 1

5

If you're publishing to the filesystem, then you'll need to set the Component Template to output JSP, use the ComponentPresentationAssembler class and ensure that the DCPs are being published to a sub-directory of your website by the Deployer.

If you're publishing as REL, you'll need to set the Component Template to output REL, configure the Deployer to publish these to the Broker database. You could try using the PageContentAssembler class (rather than the ComponentPresentationAssembler one).

For more details please see the Content Delivery Namespaces page in the online documentation.

5
  • ISTR that you /can/ use the ComponentPresentationAssembler with REL.... although that documentation is very vague on that point, and my memory isn't 100% trustworthy. Commented Dec 5, 2016 at 7:58
  • That's interesting to know, Dominic. I've only used PageContentAssembler with REL (quite a while ago) and this worked. Commented Dec 5, 2016 at 8:41
  • I've updated my answer to clarify that you can use either PageContentAssembler or ComponentPresentationAssembler when working with REL. Commented Dec 5, 2016 at 12:08
  • Thanks Jonathan! The CT is outputted as a JSP under dcp/jsp sub-directory of the website and I'm using the ComponentPresentationAssembler, but the issue is the JSP statements in the CT aren't getting executed. It renders as-is. Commented Dec 5, 2016 at 14:56
  • What happens if you just put the write out (<% out.println("Hello"); %>) in the JSP page (and not in a DCP). I presume that it renders okay there? Is there anything in the CD log files (you may need to lower these to DEBUG)? Commented Dec 5, 2016 at 18:13

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.