File not found when calling SlingServlet from AJAX or a url



I recently migrated to AEM 6.1. In the process I had to reinstall some of my OSGI bundles.


They all worked except where I call them from AJAX.

I have a servlet that I register using

@SlingServlet(paths = "/bin/stores.json", methods = "POST", metatype = false)

Inside my class I have the following method



    protected void doGet(SlingHttpServletRequest request,
            SlingHttpServletResponse response) throws ServerException,
            IOException {
        try {
            // http://localhost:4502/bin/stores.json?lat=-33.9168959&lng=18.418187&uid=1
            String storeUid = request.getParameter("uid");



I have checked that my osgi bundle is active on



When I call the following



I get back

<html> <head> <title>File not found</title> </head> <body> <p>A custom errorhandler for 404 responses</p> </body> </html>


Do I have to define the path /bin/stores.json in one of the configuration interfaces on http://localhost:4502/system/console/configMgr


I looked at

Apache Sling Servlet / Script Resolver and Error handler with no success.

Please can anyone advice

Clive Stewart

Accepted Solutions (1)

Accepted Solutions (1)


Community Manager


Hi Clive Stewart

As pointed correctly by Awadesh, you should either change method to “GET” or implement your logic in “doPost” method.

Please have a look at the article link: -


Brief about this article


This article covers Submitting Adobe CQ form data to java Sling Servlets using POST method.

So Basically here we are doing AJAX POSTrequest :-


         type: 'POST',   


         data:'id='+ claimId+'&firstName='+ myFirst+'&lastName='+ myLast+'&address='+ address+'&cat='+ cat+'&state='+ state+'&details='+ details+'&date='+ date+'&city='+ city,

         success: function(msg){

           alert(msg); //display the data returned by the servlet




And OSGI java code is handling it by:-

protected void doPost(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServerException, IOException {     

<Code Logic>



I hope this will solve your problem.


Thanks and Regards

Kautuk Sahni

Answers (4)

Answers (4)



you have defined your servlet to respond to POST requests but it looks like you are doing a GET. try adding GET to methods as following

methods = { "GET", "POST" }

if you still get error. look into error.log to find out what happened.