如何在servlet中为特定页面创建WCMUsePojo实例? [英] How can I create an instance of WCMUsePojo in a servlet for a specific page?

查看:97
本文介绍了如何在servlet中为特定页面创建WCMUsePojo实例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在servlet中创建WCMUsePojo的实例。实现类已在可见模板中使用。我在下面尝试过代码,但无法正常工作。有任何想法吗?

I am trying to create an instance of WCMUsePojo in a servlet. The implementing class is already used in sightly templates. I have tried code below and could not get it to work. Any ideas? Thanks.

    @Override
protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws IOException {

    try {
        Resource     resource = request.getResource().getResourceResolver().getResource
                ("/content/mynewsite/homepage");
        WCMUsePojo template = resource.adaptTo(BaseTemplate.class);
        template.getPageManager(); // Does not work
    } finally {
        log.error("Error processing servlet");
    }
}


推荐答案

I也有类似的问题。在测试中,我发现下面的模式似乎实例化了WCMUsePojo类。我不知道您的情况需要什么绑定。

I have a similar problem. in my tests I found the pattern below seems to instantiate WCMUsePojo classes. I don't know what bindings are needed in your case.

BaseTemplate template = new BaseTemplate();
SimpleBindings bindings = new SimpleBindings();
bindings.put("resource", resource);
template.init(bindings);

这篇关于如何在servlet中为特定页面创建WCMUsePojo实例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆