从动态选择下拉列表的cq5对话框调用时,吊索servlet给出错误

时间:2015-01-15 14:17:19

标签: servlets cq5 sling

我创建了一个servlet,它返回一个JSON,其中包含要在下拉列表中添加的选项。我使用节点下的options参数设置此servlet的路径。

下拉列表调用servlet。我也可以通过以下网址手动测试:localhost:4502/bin/myServlet/。它调用我的servlet并打印JSON结果。然而,还有一个错误消息:

  

{“text”:“abcd”,“value”:“xyz”,“text”:“abcd”,“value”:“xyz”}

     

不支持方法GET

     

无法在com.marsh.newsLatest.servlets.TagLocatorServlet中向/ bin / tagFinder提供请求   请求进度:

 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
     

(...)

如何摆脱错误?

servlet代码可以在下面找到:

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

    }
}

1 个答案:

答案 0 :(得分:1)

错误由superclass中定义的doGet()方法产生。从doGet()实施中删除最后一行,错误应该消失:

super.doGet(request, response);