我创建了一个jsp页面,在其中我加载了一组带有数据库值的文本框。我需要每隔5秒刷新一次这个页面。我尝试使用元标记,但它会导致退出。我猜它是因为会话变量被破坏了。有人可以指点我正确的方向吗?提前谢谢......
答案 0 :(得分:0)
示例代码:
我在上一页设置了会话,我在使用元标记自动刷新后得到它。
JSP:
<meta http-equiv="refresh" content="10; url=main.jsp">
<%
String title = "Welcome Back to my website";
Integer visitCount = new Integer(0);
String visitCountKey = new String("visitCount");
String userIDKey = new String("userID");
String userID = new String("No User");
if (session.getAttribute(userIDKey)!=null){
System.out.println("Found Session Attribute");
visitCount = (Integer) session.getAttribute(visitCountKey);
if(visitCount!=null)
visitCount = visitCount + 1;
else
visitCount = 1;
userID = (String)session.getAttribute(userIDKey);
session.setAttribute(visitCountKey, visitCount);
} else {
System.out.println("New Session");
title = "Welcome to my website";
session.setAttribute(userIDKey, userID);
session.setAttribute(visitCountKey, visitCount);
}
%GT;
Hi <%= userID%> <%=title %>
Visit Count <%= visitCount%>