我将包含 servlet 的 bundle 上传到 Sling
@SlingServlet(
name = "Servlet for CRUD operations",
methods = {"GET", "POST"},
// resourceTypes = "/apps/practice",
paths = "/content/practice",
extensions = {"html", "json"}
)
public class CRUDServlet extends SlingAllMethodsServlet {
@Reference
private CRUDService crudService;
如果我有http://localhost:8080/content/practice的“路径”,我就可以得到它。也许是一个愚蠢的问题,但是如果我有“resourceTypes”,我需要在地址栏中输入什么才能获取它?
PS 抱歉我的英语不好,我来自俄罗斯:)
最佳答案
在 Sling 中部署 servlet 有两种方法:
- 路径绑定(bind),就像您示例中的路径
- 资源类型绑定(bind)
当 Servlet 绑定(bind)到资源类型时,当访问具有该资源类型的资源时,将为其提供服务。作为一个简单的示例,假设您在 /content/practice/hello
处有一个资源,其 sling:resourceType 属性值为 practice/example
。
servlet 注册必须针对 resourceTypes="practice/example"
并在访问资源时调用,例如http://localhost:8080/content/practice/hello.html .
有关更多详细信息,请参阅Sling documentation on resources and scripts还有Sling documentation on URL to script resolution .
关于java - 如何在Sling中找到服务器上的servlet?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51408076/