AEM 6.2 invoke JSP code after HTTP POST request
Hi All,
Is it possible to invoke JSP code in AEM 6.2 following an HTTP POST request?
I have managed to get it working for HTTP GET but I can’t get it working for HTTP POST.
I have listed below the steps I have gone through so far to get JSP code running with HTTP GET and to try to get it working with HTTP POST.
Thank you for you help,
Best regards,
Robert
————
Here are the steps I have gone through so far :-
1. In browser, navigate to http://localhost:4502/crx/de/index.jsp#/apps
2. Create a Component called “simpleCounterIncrementer”
3. Paste the JSP code below into “simpleCounterIncrementer.jsp”
<%@ page import = "javax.jcr.*,org.apache.sling.api.SlingHttpServletRequest,org.apache.sling.api.resource.ResourceResolver,org.apache.sling.api.resource.Resource" %>
<%
final String simpleCounterNode = "simpleCounterNode";
final SlingHttpServletRequest slingRequest = (SlingHttpServletRequest) request;
final ResourceResolver resourceResolver = slingRequest.getResourceResolver();
final Resource resource = resourceResolver.getResource("/content");
Node node = resource.adaptTo(Node.class);
if (node.hasNode(simpleCounterNode))
{
node = node.getNode(simpleCounterNode);
}
else
{
node.addNode(simpleCounterNode);
node.save();
node = node.getNode(simpleCounterNode);
}
final String simpleCounterProperty = "simpleCounterProperty";
if (!node.hasProperty(simpleCounterProperty))
{
node.setProperty(simpleCounterProperty, 0);
}
final Property counterProperty = node.getProperty(simpleCounterProperty);
counterProperty.setValue(counterProperty.getLong() + 1);
counterProperty.save();
%>
4. In browser, navigate to http://localhost:4502/crx/de/index.jsp#/content
5. Create a Node called “simpleCounterIncrementer” and set “jcr:primaryType” = “cq:Page”
6. Create a sub-Node called “jcr:content” and set “jcr:primaryType” = “cq:PageContent” and set “sling:resourceType” = “simpleCounterIncrementer”
7. Open a terminal window and run the command below FIVE times
curl --user admin:admin -X GET http://localhost:4502/content/simpleCounterIncrementer.html
8. In browser, navigate to http://localhost:4502/crx/de/index.jsp#/content/simpleCounterNode and observe "simpleCounterProperty" in 5 because HTTP GET has run five times
9. In browser, navigate to http://localhost:4502/crx/de/index.jsp#/apps/simpleCounterIncrementer
10. Copy “simpleCounterIncrementer.jsp” and paste it as “simpleCounterIncrementer.POST.jsp”
11. Open a terminal window and run the command below
curl --user admin:admin -X POST http://localhost:4502/content/simpleCounterIncrementer.html
12. In browser, navigate to http://localhost:4502/crx/de/index.jsp#/content/simpleCounterNode and observe "simpleCounterProperty" in still 5 even though HTTP POST has run
Please can you advise if it is possible to invoke JSP code in AEM 6.2 following an HTTP POST request?
Please can you advise what additional steps I need?
Thank you for your time,
Best regards,
Robert