无法在Adode CQ5中发布表单

Hit*_*esh 1 adobe aem

我是AdobeCQ5的新手.我在发布表格时遇到一些麻烦.这是我的结构 -

/apps/<myproject>/components/mytestcomponent
Run Code Online (Sandbox Code Playgroud)

mytestcomopnent.jsp有以下代码 -

<form id="myForm"  action="<%=resource.getPath()+".html" %>">
    <input type="text" id="t1" class="input-small" placeholder="Temprature F" />
    <input type="text" id="t2" class="input-small" placeholder="Temprature C" readonly/>
    <button type="button" id="cbtn" class="btn">Convert</button>
</form>

<script>
    $(document).ready(function() {
        $('#cbtn').click(function ()  {        
            var URL = $("#myForm").attr("action");   
            alert(URL); 
            var t1=$("#t1").val();
            var t2=$("#t2").val();
            $.ajax({
                url: URL,
                data:{'t1':t1},
                type:"post",
                success: function(data, status) {
                    $("#t2").val(data);
                },
                error: function( xhr, txtStat, errThrown ) {
                    alert("ajax  error! " + txtStat + ":::" + errThrown);
                }
            }); 
        }); 
    });    
</script>
Run Code Online (Sandbox Code Playgroud)

这是我的响应代码200(成功),但不需要输出.我的mycomponent.POST.jsp有以下代码 -

<%
    // TODO add you code here
    String t1=request.getParameter("t1");
%>
<%= t1 %>
Run Code Online (Sandbox Code Playgroud)

它给出了以下输出

  Content modified /content/imobile/en/jcr:content/social.html
  Status    
  200
  Message   
  OK
  Location     /content/imobile/en/_jcr_content/social.html
  Parent Location  /content/imobile/en/_jcr_content
  Path  
  /content/imobile/en/jcr:content/social.html
  Referer http://example.comt:4502/content/imobile/en.html
  ChangeLog 
 <pre></pre>
 Go Back
 Modified Resource
 Parent of Modified Resource
Run Code Online (Sandbox Code Playgroud)

请帮忙解决这个问题.

Tom*_*wek 6

处理组件的POST方法的JSP文件应该命名POST.jsp而不是mycomponent.POST.jsp.

请注意,如果您拦截了对组件的所有POST请求,您将无法使用对话框在作者实例上编辑它(因为对话框只是将数据POST到组件URL).要避免它,请考虑使用自定义选择器(如form).您的表单应该看起来像这样声明:

<form id="myForm" action="${resource.path}.form.html">
Run Code Online (Sandbox Code Playgroud)

并且应该调用处理POST请求的脚本form.POST.jsp.

第二个重要的是你应该使用Java类而不是JSP文件来存储业务逻辑.在这种情况下,它意味着form.POST.jsp可以使用声明如下的Sling servlet替换脚本:

@SlingServlet(
    resourceTypes="myproject/components/mytestcomponent",
    methods="POST",
    selectors="form")
Run Code Online (Sandbox Code Playgroud)