Thursday, 30 September 2021

creating sling servlet with path parameter in AEM

There is no direct way to do this as aem is not supporting path parameter in sling servlet, but we can do it by following way

On dispatcher write a rules as below which will convert your service to path parameter based service from query parameter based service.

if we want to convert out service let say 

myUrl/?p1=P1value&p2=P2value&p3=P3value 

above service to path parameter based service then we can do it by writing below rule in dispatcher. 

myUrl/(P1PossibleValueRegex)/(P2PossibleValueRegex)/(P3PossibleValueRegex) myUrl/?p1=$1&p2=$2&p3=$3 [PT]

I Hope this will help

Your feedback will help others please share your feedback

AEM caching the query parameter of service url

 There is no direct way to cache the query parameter in the dispatcher, but we can do it by following way

on dispatcher write a rules as below which will convert your service to path parameter based service from query parameter based service.

and path is automatically get cached so our problem is solved.

myUrl/(P1PossibleValueRegex)/(P2PossibleValueRegex)/(P3PossibleValueRegex) myUrl/?p1=$1&p2=$2&p3=$3 [PT]

I Hope this will help

Your feedback will help others please share your feedback