AEMAaCS | Extension less and selector less sling servlet | Community
Skip to main content
Level 2
September 21, 2022
Solved

AEMAaCS | Extension less and selector less sling servlet

  • September 21, 2022
  • 2 replies
  • 907 views

Hi Folks,

 

I need to write a sling servlet either part type or resource type anything is acceptable

1. Extension less

2. Selector less

 

Something like below

localhost:4502/mysite?param1=val1&param2=val2

 

Path type servlet always need 2 level of hierarchy i.e.  /bin/ or /mysite/, Can it have path without trailing slash and only one level of script resolution like /mysite

I tried but no luck.

 

Please advise

 

Thanks,

Pradeep

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by joerghoh

The problem with these URLs is that the dispatcher is not able to cache a URL without an extension. That means you should rewrite your URLs on the dispatcher to contain extensions.

 

(And of course query strings also prevent the dispatcher from caching the files...)

 

2 replies

TarunKumar
Community Advisor
Community Advisor
September 21, 2022

Hi @pradeepdubey 

Can you please check if you have specified the path in Apache Sling Servlet / Script Resolver and Error Handler in config manager console if you registering the servlet through path.
Also you should be able to register it through resourceType, please share the code snippet of your ajax call and servlet registration.

Level 2
September 21, 2022

It is registered in osgi config error handler.

/mysite

Hoever it is not working.

It is working when I register as 

/mysite/

and servlet path as /mysite/myservlet then it is working.

 

My requirement is to make the sling servlet working at path /mysite only.

localhost:4502/mysite?param1=val1

 

Code is given below 


@8220494(service=Servlet.class,
property={
Constants.SERVICE_DESCRIPTION + "=Mysite Servlet",
"sling.servlet.methods=" + HttpConstants.METHOD_GET,
"sling.servlet.paths=/mysite"
})
public class MySiteServlet extends SlingSafeMethodsServlet {

private static final long serialVersionUID = 1L;
private transient Logger log = LoggerFactory.getLogger(MySiteServlet.class);


@9944223
protected void doGet(final SlingHttpServletRequest req,
final SlingHttpServletResponse resp) throws ServletException, IOException {
log.info("Entering doGet");
String val1 = req.getParameter("param1");
log.info("val1 {}", val1);
}
}

joerghoh
Adobe Employee
joerghohAdobe EmployeeAccepted solution
Adobe Employee
September 24, 2022

The problem with these URLs is that the dispatcher is not able to cache a URL without an extension. That means you should rewrite your URLs on the dispatcher to contain extensions.

 

(And of course query strings also prevent the dispatcher from caching the files...)