gpt4 book ai didi

java - cq5无法创建servlet资源

转载 作者:行者123 更新时间:2023-12-01 18:36:38 25 4
gpt4 key购买 nike

我在 CQ5 应用程序中创建一个 servlet:

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;

@SlingServlet(
label = "Example Servlet",
paths = {"/bin/project/signin"},
methods = {"GET"},
extensions = {"html"},
metatype = false
)
public class SignInServlet extends SlingAllMethodsServlet {

private static final long serialVersionUID = 796802690004962223L;

@Override
protected void doGet(SlingHttpServletRequest request,
SlingHttpServletResponse response) throws ServletException,
IOException {
doPost(request, response);
}

@Override
protected void doPost(SlingHttpServletRequest request,
SlingHttpServletResponse response) throws ServletException,
IOException {
response.setContentType("text/plain");
response.getOutputStream().print("Sigin Servlet");
}
}

我尝试通过rest-client调用它,但它返回:

No resource found for url: http://localhost:4502/bin/project/signin

我还在Felix端打开Sling Resource Resolver来测试它是否可用。但我收到了:

NonExistingResource, path=/bin/project/signin

/bin/ 已在 Fellix 的 Apache Sling Servlet/脚本解析器和错误处理程序中进行配置

最佳答案

@SlingServlet 注释中,您已声明此 servlet 仅支持带有 .html 扩展名的请求,因此您应该点击以下 URL:

http://localhost:4502/bin/project/signin.html

如果您不想使用该扩展,请从 servlet 注释中删除适当的参数。

关于java - cq5无法创建servlet资源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21695519/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com