usercounter.jsp

来自「精通从JavaScript到Jsp范例程序设计」· JSP 代码 · 共 49 行

JSP
49
字号
<%@ page language="java" isThreadSafe="true" %>
<%@ page import="java.util.*"  %>
<%@ page import="java.text.*"  %>
<%! 
	Hashtable userTable = new Hashtable(); 
	int totalCount=0;	
	
	public String getNowDate(){
		SimpleDateFormat formatter = 
		    new SimpleDateFormat ( "yyyy/MM/dd a hh:mm:ss", Locale.US );
      		Date currentTime = new Date();
		return formatter.format(currentTime);
	}
				
  public int getCount( String userName ){
    Integer count = (Integer)userTable.get( userName );
    if( count != null ){ 
      int nowCount = count.intValue() + 1;
      userTable.put( userName, new Integer( nowCount ) ); 
      return nowCount;
    }		
    userTable.put( userName, new Integer( 1 ) );
    return 1;
  }
    	
  public void delay( long millis ){
  	try{
  		Thread.sleep( millis );
  	}
  	catch( InterruptedException intex ){
  	}	
  }      
%>
<% 
	String username = request.getParameter( "textUserName" );
	int count = getCount( username );
	int localTotalCount;
	synchronized( this ){
		localTotalCount = ++totalCount;
	}
%>
<html>
<head>
<title>Login Counter</title>
<meta http-equiv="Content-Type" content="text/html; charset=big5">
</head>
<body bgcolor="#FFFFFF">
<div align="center"> 
  <p><font color="#0000FF">瞷

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?