我是AdobeCQ5的新手。我在发布表格时遇到一些麻烦。这是我的结构 -
/apps/<myproject>/components/mytestcomponent
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>
这是我的响应代码200(成功),但不需要输出。我的mycomponent.POST.jsp有以下代码 -
<%
// TODO add you code here
String t1=request.getParameter("t1");
%>
<%= t1 %>
它提供以下输出
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
请帮忙解决此问题。
答案 0 :(得分:6)
处理组件POST方法的JSP文件应命名为POST.jsp
而不是mycomponent.POST.jsp
。
请注意,如果您拦截了对组件的所有POST请求,您将无法使用对话框在作者实例上编辑它(因为对话框只是将数据POST到组件URL)。为避免这种情况,请考虑使用自定义选择器(如form
)。您的表单看起来应该像这样声明:
<form id="myForm" action="${resource.path}.form.html">
并且应该调用处理POST请求的脚本form.POST.jsp
。
第二个重要的是你应该使用Java类而不是JSP文件来存储业务逻辑。在这种情况下,这意味着form.POST.jsp
脚本可以替换为声明如下的Sling servlet:
@SlingServlet(
resourceTypes="myproject/components/mytestcomponent",
methods="POST",
selectors="form")