我有一个按预期响应GET请求的Servlet。问题是我的Servlet没有处理POST请求,而是根据/system/console/requests
由SlingPostServlet处理。我的Servlet正在使用SCR注释。
@SlingServlet(
methods = {"POST","GET"},
resourceTypes = {"company/components/pages/thepage"},
extensions = { "html" },
selectors = { "edit" },
generateService = true,
generateComponent = true,
name = "com.company.services.osgi.package.EditServlet",
label = "Profile Update Handler"
)
@Properties({
@Property(name = "service.vendor", value = "Our Company"),
@Property(name = "service.description", value = "Update Handler") })
public class EditServlet extends SlingAllMethodsServlet {
...
@Override
protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response){
// during GET requests this code works!
}
@Override
protected void doPost(SlingHttpServletRequest request, SlingHttpServletResponse response){
// during POST requests this code is not executing
}
我在http://localhost:4502/system/console/components中看到我的servlet属性已设置且处于活动状态
component.id = 3463
component.name = com.company.services.osgi.package.EditServlet
sling.servlet.methods = [POST, GET]
sling.servlet.resourceTypes = [company/components/pages/thepage]
sling.servlet.selectors = [edit]
sling.servlet.extensions = [html]
安装捆绑包时,我没有看到错误。它们似乎都是注册
15.07.2015 13:05:24.017 INFO [OsgiInstallerImpl] org.apache.sling.servlets.resolver.internal.SlingServletResolver已注册的ServletResourceProvider:servlet = com.company.services.osgi.package。 EditServlet,paths = [/ libs / foundation / components / primary / company / components / pages / thepage / edit.html.POST.servlet,/libs/foundation/components/primary/company/components/pages/thepage/edit.html .GET.servlet]
我已经确认该页面具有正确的resourceType(如果没有,那么我认为doGet也不会正常工作)。我怎么错了POST?任何想法为什么doGet工作,但doPost不?
更新
我能够实现这个工作的唯一方法是为resourceTypes = {"sling/servlet/default" },
操作的doPost创建另一个servlet我更新了第一个从方法中删除POST的servlet
@SlingServlet(
methods = {"POST"},
// resourceTypes = {"company/components/pages/thepage"},
resourceTypes = {"sling/servlet/default" },
extensions = { "html" },
selectors = {"post-servlet"} ,
generateService = true,
generateComponent = true,
name = "com.company.services.osgi.people.UpdateServlet",
label = "Update Handler",
metatype=true
)
答案 0 :(得分:2)
我们没有看到您的POST请求的示例,但我猜您可能正在POST到页面路径,而您的servlet注册的资源类型位于子资源jcr:content上。
使用cq:Page资源上的html扩展名的GET请求在内部重定向到jcr:content资源的html呈现,但POST请求没有这样的内容。
答案 1 :(得分:0)
您正在使用哪个AEM版本,因为来自6.x POST请求在CSRF令牌过滤器中定义。如果版本是6.x,则将其从CSRF过滤器配置中删除或添加具有属性依赖性的CQ.jquery clientlib。它将自动处理这个过滤器。