gpt4 book ai didi

servlets - 在 CQ5 中访问 Sling Servlet

转载 作者:行者123 更新时间:2023-12-02 21:57:55 25 4
gpt4 key购买 nike

我们在 CQ5 中创建了一个 Simple Sling Servlet 作为 OSGI bundle (使用 cqblueprits/maven/eclipse)。

    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.SlingSafeMethodsServlet;

@SlingServlet(methods = { "GET" }, paths = { "/bin/acme/my/servlet" }, extensions = { "html" })
public class HelloWorld extends SlingSafeMethodsServlet {
private static final long serialVersionUID = 217529099388338070L;

@Override
protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException,
IOException {
response.setContentType("text/plain");
response.getOutputStream().print("Hello AbsoluteUrlServlet World!");
}
}

如果使用浏览器从浏览器发出请求,则购买

    http://localhost:4502/bin/acme/my/servlet

我收到错误

    No resource found

Cannot serve request to /bin/acme/my/servlet in /libs/sling/servlet/errorhandler/404.jsp
Request Progress:

0 (2014-04-18 13:53:24) TIMER_START{Request Processing}
0 (2014-04-18 13:53:24) COMMENT timer_end format is {<elapsed msec>,<timer name>} <optional message>
0 (2014-04-18 13:53:24) LOG Method=GET, PathInfo=/bin/acme/my/servlet
0 (2014-04-18 13:53:24) TIMER_START{ResourceResolution}
0 (2014-04-18 13:53:24) TIMER_END{0,ResourceResolution} URI=/bin/acme/my/servlet resolves to Resource=NonExistingResource, path=/bin/acme/my/servlet
0 (2014-04-18 13:53:24) LOG Resource Path Info: SlingRequestPathInfo: path='/bin/acme/my/servlet', selectorString='null', extension='null', suffix='null'
0 (2014-04-18 13:53:24) TIMER_START{ServletResolution}
0 (2014-04-18 13:53:24) TIMER_START{resolveServlet(NonExistingResource, path=/bin/acme/my/servlet)}
1 (2014-04-18 13:53:24) LOG {0}: no servlet found
1 (2014-04-18 13:53:24) TIMER_END{1,resolveServlet(NonExistingResource, path=/bin/acme/my/servlet)} Using servlet org.apache.sling.servlets.get.DefaultGetServlet
1 (2014-04-18 13:53:24) TIMER_END{1,ServletResolution} URI=/bin/acme/my/servlet handled by Servlet=org.apache.sling.servlets.get.DefaultGetServlet
1 (2014-04-18 13:53:24) LOG Applying Requestfilters

在CQ的错误日志中,我们可以看到

    18.04.2014 14:19:53.879 *INFO* [0:0:0:0:0:0:0:1 [1397855993874] GET /apps/path/to/my/servlet HTTP/1.1] org.apache.sling.engine.impl.SlingRequestProcessorImpl service: Resource /apps/path/to/my/servlet not found

我无法在 CQ 中部署任何自定义 SlingServlet。为了使用 servlet 打包 bundle ,我使用 Eclipse/Maven/cqblueprints 组合。

请给我们一些解决问题的建议。

最佳答案

如果上面发布的代码是您的 servlet 的完整代码,那么它甚至可能由于缺少导入而无法编译。

如果所有导入都正确并且 servlet 编译正常,则检查该组件是否在 /system/console/components 下注册。在 Felix 控制台中并且处于事件状态。

由于提到的 servlet 路径是/bin/acme/my/servlet,因此您无需在脚本解析器中注册该路径,因为默认情况下会注册/bin/。但如果您使用自定义路径,例如/apps/xyz/abc,请确保您已在 Apache Sling Servlet/Script Resolver and Error Handler 中注册该路径。配置可在 /system/console/configMgr 下找到

关于servlets - 在 CQ5 中访问 Sling Servlet,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23162360/

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