2016-08-15 48 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