Expand my Community achievements bar.

SOLVED

AEMAaCS | Extension less and selector less sling servlet

Avatar

Level 2

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

1 Accepted Solution

Avatar

Correct answer by
Employee Advisor

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...)

 

View solution in original post

3 Replies

Avatar

Community Advisor

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.

Avatar

Level 2

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 


@component(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);


@Override
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);
}
}

Avatar

Correct answer by
Employee Advisor

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...)