I created a servlet that returns a JSON containing options to add in a dropdown. I set this servlet's path using the options
parameter under the node.
The servlet is called by the dropdown. I can also test it manually via the URL: localhost:4502/bin/myServlet/
. It calls my servlet and prints the JSON result. However along with that there is also an error message:
{"text":"abcd","value":"xyz","text":"abcd","value":"xyz"}
Method GET not supported
Cannot serve request to /bin/tagFinder in com.marsh.newsLatest.servlets.TagLocatorServlet Request Progress:
0 (2015-01-15 19:40:47) TIMER_START{Request Processing} 0 (2015-01-15 19:40:47) COMMENT timer_end format is {<elapsed msec>,<timer name>} <optional message> 0 (2015-01-15 19:40:47) LOG Method=GET, PathInfo=/bin/tagFinder
(...)
How can I get rid of the error?
The servlet code can be found below:
package com.abc.newsLatest.servlets;
import java.io.IOException;
import javax.servlet.ServletException;
import org.apache.felix.scr.annotations.sling.SlingServlet;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.SlingHttpServletResponse;
import org.apache.sling.api.servlets.SlingAllMethodsServlet;
import org.apache.sling.api.servlets.SlingSafeMethodsServlet;
import org.apache.sling.commons.json.JSONException;
import org.apache.sling.commons.json.io.JSONWriter;
/**
*
*
*/
@SlingServlet(paths = "/bin/tagFinder",methods="get")
public class TagLocatorServlet extends SlingAllMethodsServlet {
private static final long serialVersionUID = -3960692666512058118L;
@Override
protected void doGet(SlingHttpServletRequest request,
SlingHttpServletResponse response) throws ServletException,
IOException {
// TODO Auto-generated method stub
System.out.println("in get method ");
response.setContentType("application/json");
JSONWriter writer = new JSONWriter(response.getWriter());
try {
writer.object();
// {
writer.key("text").value("allhad");
writer.key("value").value("nilekar");
writer.key("text").value("allhad");
writer.key("value").value("nilekar");
writer.endObject(); // }
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
super.doGet(request, response);
}
@Override
protected void doPost(SlingHttpServletRequest request,
SlingHttpServletResponse response) throws ServletException,
IOException {
// TODO Auto-generated method stub
System.out.println("in post");
this.doGet(request, response);
}
}