代码如下:
public class ServerInformationServlet extends HttpServlet {
private static int cnt=0;
public void init()throws ServletException{
cnt++;
}
public void doGet(HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException{
response.setContentType( "text/html;charset=gb2312 ");
PrintWriter out=response.getWriter();
sychronized(cnt){
cnt++;
}
out.println( " <body> ");
out.println( " <font face=宋体 color=red size=15> 这是您第 "+cnt+ "次访问 </font> ");
out.println( " </body> </html> ");
}
}
提示sychronized(cnt)为自定义方法
------解决方案--------------------
synchronized