jsp achieve session count

jsp achieve session count

First, write java code in the jsp

<%
    Integer count_today = (Integer)session.getAttribute("COUNT");
    if ( count_today == null ) {
        count_today = new Integer(1);
        session.setAttribute("COUNT", count_today);
    }
    else {
        count_today = new Integer(count_today.intValue() + 1);
        session.setAttribute("COUNT", count_today);
    }
//    out.println("<div><b>日访问量: " + count_today + " 次</b></div>");
%>

 

Second, the page assignment

日访问量:<span><%=count_today%></span>

 

Third, to achieve results

 

Guess you like

Origin www.cnblogs.com/Michelle20180227/p/12334680.html