数字计数器问题,急,帮帮忙!!

gougou606 2005-03-18 05:15:59
不知道哪里有错?帮我运行一下,然后该该!!

<html>
<head>
<title>数字记数器</title>
</head>
<body color="#ffffff">
<%@ page import="java.io.*">
<% BufferedReader file;
String countFile="http://localhost:8080/FirstProject/count.txt";
file=new BufferedReader(new FileReader(countFile));
String readfile=null;
int writefile=1;
try{
readfile=file.readLine();
}
catch(IOException e){
out.print("数据错误!");
}
if(readfile==null)readfile="没有记录";
else
writefile=Integer.parseInt(readfile)+1;


try{
PrintWriter pw;
pw=new PrintWriter(new FileOutputStream(countFile));
pw.println(writefile);
pw.close();
}
catch(IOException e){
out.print(e.getMessage());
}
%>
<div align="center">
<p><font size="5">数字记数器:</font></p>
<p>
<font size="4" color="blue">你是本站的第</font>
<font size="5" color="red"><%=readfile%></font>
<font size="4" color="blue">位访问者!</font>
</p>
</div>
</body>
</html>
...全文
97 3 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
thrive_li 2005-03-18
  • 打赏
  • 举报
回复
<%@ page import="java.io.*"%>
<html>
<body >
<% BufferedReader file;
String countFile="c:/count.txt";
file=new BufferedReader(new FileReader(countFile));
String readfile="1qqqqqqqq";
int writefile=1;
try{
readfile=file.readLine();
}
catch(IOException e){
System.out.println("@@@@@@@@");
e.printStackTrace();
out.print("数据错误!");
}
if(readfile==null)readfile="没有记录";
else
writefile=Integer.parseInt(readfile)+1;


try{
PrintWriter pw;
pw=new PrintWriter(new FileOutputStream(countFile));
pw.println(writefile);
pw.close();
}
catch(IOException e){

e.printStackTrace();
out.print(e.getMessage());

}

%>
<p>
welcome you are <%=readfile%> user.
</p>
</body>
</html>
thrive_li 2005-03-18
  • 打赏
  • 举报
回复
1.<%@ page import="java.io.*"> 改为<%@ page import="java.io.*"%>
2.String countFile="http://localhost:8080/FirstProject/count.txt";
写绝对路径比如:"c:\\count.txt",
thrive_li 2005-03-18
  • 打赏
  • 举报
回复
报什么错啊?有没有先创建FirstProject/count.txt?

81,122

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧