2016-08-15 57 views
0

servlet代码看起来像下面表单提交的Servlet AEM

@SlingServlet(
     methods = {"POST"}, 
     resourceTypes = {"cq:Page"}, 
     extensions = {"html"}) 
public class AssetDownloadServlet extends SlingAllMethodsServlet { 

    private static final Logger log = LoggerFactory.getLogger(AssetDownloadServlet.class); 


    @Override 
    protected void doPost(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException 
    { 
     log.info("%%%%%%%%%%%%%%$$$$$$$$$$$%%%%%%%**************: "+ "doPost"); 
     processRequest(request,response); 
    } 

    @Override 
    protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException 
    { 
     log.info("%%%%%%%%%%%%%%$$$$$$$$$$$%%%%%%%**************: "+ "doGet"); 
     processRequest(request,response); 
    } 

    private void processRequest(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException{ 
     log.info("%%%%%%%%%%%%%%$$$$$$$$$$$%%%%%%%*******************"); 
     log.info(request.getParameter("format")); 
     log.info("%%%%%%%%%%%%%%$$$$$$$$$$$%%%%%%%*******************"); 
    } 
} 

在HTML页面的形式看起来像下面

<form method="POST"> 
    <fieldset> 
    <p>Format needed?</p> 
    <ul style="list-style-type:none" data-sly-list.rendition="${renditions}"> 
     <!--${rendition.path}--> 
     <li> 
     <label> 
      <input type="radio" name="format" value="${rendition.name}" /> 
      <span>${rendition.displayName}</span> 
     </label> 
     </li> 
    </ul> 
    </fieldset> 
    <fieldset> 
    <button type="submit">Start Download</button> 
    <a>Cancel Download</a> 
    </fieldset> 
</form> 

CQ详细信息页面

<!--cq{"decorated":false,"type":"myProject/components/page/generic","path":"/content/myProject/en/assetdetail/jcr:content","selectors":"IRNHUF7D","servlet":"Script /libs/foundation/components/page/page.jsp","totalTime":28,"selfTime":8}--> 

摘要:

我有一个cq:页面资源,有一个表单和servlet链接到它。但是在提交表单时,servlet并未下注。我看到在http://localhost:4502/system/console/中正确设置了属性。

请建议..

感谢

回答

0

cq:Page不是resourceType为一个,它的一个节点类型。您需要将servlet中的resourceType修改为页面的jcr:content节点中的sling:resourceType。另外需要注意的是,如果你的路径指向cq:Page node,那么你的Servlet将不会被调用,它需要指向jcr:content节点被servlet拾取。

@SlingServlet(
     methods = {"POST"}, 
     resourceTypes = {"path/to/resource/type"}, 
     extensions = {"html"}) 
public class AssetDownloadServlet extends SlingAllMethodsServlet { 

而且你的表单定义应该是这样的 -

<form method="POST" action="${currentPage.path}/_jcr_content.html"> 

注意,作为_jcr_content

+0

我尝试了你的建议jcr:content被写入。但问题依然存在。我在日志中也看不到任何更改。 – phemanthkumar28

+0

我的不好,我修改了上面我的回复中的网址,其 /_jcr_content.html而不是 ._jcr_content.html –

+0

我甚至试过这个,它不太好。我在上面的代码片段中添加了我在页面上收到的CQ信息。 – phemanthkumar28