[英]Getting response form custom @proceesAction in WebSphere Portal Portlet
我正在WebSphere Portal 8中開發Portlet,並且在從自定義@processAction方法獲取響應時遇到問題,該方法被調用並執行,但是在jsp中,我無法獲取返回的數據...
我有一個jsp文件,它具有:
-portlet actionURL的定義...
<portlet:defineObjects/>
<portlet:actionURL var="cargarListadoConcursosURL">
<portlet:param name="<%=ActionRequest.ACTION_NAME%>" value="cargarListadoConcursos" />
</portlet:actionURL>
-javascript方法和ajax post方法:
<script type="text/javascript">
$(document).ready(function() {
cargarListadoConcursos();
});
function cargarListadoConcursos() {
$.ajax({
url : '<%=cargarListadoConcursosURL%>',
type : 'POST',
dataType : 'json',
success : function(data) {
alert(data);
//do something!!!
}
});
}
我的portlet類如下所示:
public class ListadoConcursosPortlet extends GenericPortlet
{
//more methods...
@ProcessAction(name="cargarListadoConcursos")
public void cargarListadoConcursos(ActionRequest request, ActionResponse response) throws PortletException, IOException {
HttpServletResponse resp = PortletUtils.getHttpServletResponse(response);
resp.setContentType("application/json");
resp.setCharacterEncoding("UTF-8");
PrintWriter writer = resp.getWriter();
writer.append(gson.toJson(new ArrayList<Concurso>()));
writer.flush();
resp.flushBuffer();
System.out.println("Paso por cargarListadoConcursos");
}
}
我認為portlet.xml很好,因為jsp調用了portlet cotroller(syso出現在控制台上)...
好吧,結論是,問題是我無法在我的JavaScript中獲得Json對象,並且永遠不會執行alert(data)...
在此先感謝您的提示!!!
問題是當您訪問actionURL時頁面會刷新。 您需要使用Resource Serving Portlet,serveResource方法和resourceURL,它們在被調用時不會刷新頁面。
使用serveResource()....並從jsp使用resourceURL
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.