我想创建Portlet来监控某些东西,所以它需要每隔一段时间自动刷新portlet页面,我怎样才能实现这一点?我一直在尝试使用普通方法,例如使用 Javascript,但它不起作用...谢谢,请给我例子:(
任何帮助将非常感激 我正在尝试使用普通的 jsp 代码,但它无法运行
<%@ page import="java.io.*,java.util.*" %>
<html>
<head>
<title>Auto Refresh Header Example</title>
</head>
<body>
<center>
<h2>Auto Refresh Header Example</h2>
<%
// Set refresh, autoload time as 5 seconds
response.setIntHeader("Refresh", 5);
// Get current time
Calendar calendar = new GregorianCalendar();
String am_pm;
int hour = calendar.get(Calendar.HOUR);
int minute = calendar.get(Calendar.MINUTE);
int second = calendar.get(Calendar.SECOND);
if(calendar.get(Calendar.AM_PM) == 0)
am_pm = "AM";
else
am_pm = "PM";
String CT = hour+":"+ minute +":"+ second +" "+ am_pm;
out.println("Crrent Time: " + CT + "\n");
%>
</center>
</body>
</html>
问候
丹尼尔
最佳答案
我设法使用此代码解决此问题
<%@page import="com.liferay.portal.kernel.portlet.LiferayWindowState"%>
<%@page import="java.util.Date"%>
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/JavaScript">
<!--
function timedRefresh(timeoutPeriod) {
$.post('<portlet:renderURL windowState="<%= LiferayWindowState.EXCLUSIVE.toString() %>"></portlet:renderURL>', function(data){
$("#myportlet").html(data);
})
}
timedRefresh(5000);
// -->
</script>
<div id="myportlet"><%= new Date() %></div>
感谢@boky,他给了我解决这个问题的主要思路:)
问候
丹尼尔
关于java - 自动刷新Portlet Liferay 6.0(定期刷新),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18714528/