⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 counter2.jsp

📁 机械工业出版社的《jsp2.0动态网站开发实例指南》的源代码
💻 JSP
字号:
<!--counter1.jsp-->
<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="java.io.*"%>
<html>
<head>
<title>counter</title>
</head>
<body>
	<%
		int temp=1;
		Integer userNum;
		if(session.isNew()){
			File f=new File("E:/temp","counter.txt");
			try{
				FileInputStream fin=new FileInputStream(f);
				DataInputStream dataIn=new DataInputStream(fin);
				temp=dataIn.readInt();
				fin.close();
				dataIn.close();
				temp+=1;
			}
			catch(FileNotFoundException e){
				out.println("file error!");
			}
			catch(IOException e){}
			
			userNum=new Integer(temp);
			application.setAttribute("userNum",userNum);
			
			try{
				FileOutputStream fout=new FileOutputStream(f);
				DataOutputStream dataOut=new DataOutputStream(fout);
				dataOut.writeInt(temp);
				fout.close();
				dataOut.close();
			}
			catch(FileNotFoundException e){
			}
			catch(IOException e){}
			
		}
		else{
			userNum=(Integer)(application.getAttribute("userNum"));
			if(userNum==null){out.println("error");}
			temp=userNum.intValue();
		}
		out.println("服务器本次开启共接待了"+temp+"位访客。<br>");
		Integer freshNum=(Integer)session.getAttribute("freshNum");
		if(freshNum==null){
			freshNum=new Integer(1);
			session.setAttribute("freshNum",freshNum);
			out.println("欢迎您的到来。<br>");
		}
		else{
			temp=freshNum.intValue()+1;
			freshNum=new Integer(temp);
			session.setAttribute("freshNum",freshNum);
			out.println("您第"+temp+"次刷新此页面。<br>");
		}
	%>
</body>
</html>

⌨️ 快捷键说明

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