liferay的MVCPortlet的ajax请求
发布时间:2020-12-16 02:11:18 所属栏目:百科 来源:网络整理
导读:1.js function redirectAndAjax(id){$.post('%=ajaxUrl%',{'portlet:namespace/id':id},function(data){ alert(data); });} 在页面上写JS引入JQUERY ,其中的ajaxUrl为在页面中定义的。定义代码为 portlet:resourceURL var="ajaxUrl" 要在json的key前加入port
1.js
function redirectAndAjax(id){ $.post('<%=ajaxUrl%>',{'<portlet:namespace/>id':id},function(data){ alert(data); }); }在页面上写JS引入JQUERY ,其中的ajaxUrl为在页面中定义的。定义代码为 <portlet:resourceURL var="ajaxUrl"> 要在json的key前加入<portlet:namespace/> 否则后台无法收到传入的参数。
jquery的文件为jquery-1.8.2.min.js 存放于 /docroot/js 目录下。 在jsp中的引入方式为在liferay-portlet.xml中的对应的portlet定义中的 <header-portlet-css>/css/main.css</header-portlet-css> 下加入行 <header-portlet-javascript>/js/jquery-1.8.2.min.js</header-portlet-javascript> 2.后台接收请求与返回值 @Override public void serveResource(ResourceRequest resourceRequest,ResourceResponse resourceResponse) throws IOException,PortletException { long id = ParamUtil.getLong(resourceRequest,"id",-1L); <pre> response.setContentType("text/html;charset=UTF-8"); PrintWriter out = null; try { out = response.getWriter(); } catch (IOException e) { e.printStackTrace(); } String result = "这是服务端返回的结果信息:"; out.println(result); out.flush(); out.close();super.serveResource(resourceRequest,resourceResponse);} (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |