<%@ page contentType="text/html;charset=gb2312"%>
<HTML>
<HEAD>
<TITLE>
计数器演示程序
</TITLE>
</HEAD>
<BODY>
<!--创建并调用bean(counter)-->
<jsp:useBean id="count" class="testcounter.counter" scope="request">
</jsp:useBean><%
//调用counter对象的ReadFile方法来读取文件lyfcount.txt中的计数
String cont=count.readFile("lyfcount.txt");
//调用counter对象的ReadFile方法来将计数器加一后写入到文件lyfcount.txt中
count.writeFile("lyfcount.txt",cont);%>
您是第<font color="red"><%=cont%></font>位访问者
</BODY>
</HTML>

解决方案 »

  1.   

    不是贴出来了吗?String cont=count.readFile("lyfcount.txt");
    count.writeFile("lyfcount.txt",cont);%
    提示错误就是找不到文件!
      

  2.   

    在当前目录开个新文件夹a,把lyfcount.txt文件放到里面。
    String cont=count.readFile("lyfcount.txt"); 改成
    String cont=count.readFile("a/lyfcount.txt");
      

  3.   

    这是哪个计数器的例子,我用weblogic,开始也是没有找到放文件的地方,我的办法是一层层的测试,把你认为的每个层都放一个,然后在看程序是针对哪个文件进行了操作,不久了然了,多试试
      

  4.   

    String cont=count.readFile("/lyfcount.txt");是放在你硬盘的根目录,如果你tomcat装在c:\tomcat那就放在c:\lyfcount.txt
      

  5.   

    D:\Webservers\Apache Tomcat 4.0\webapps\ROOT\
      

  6.   

    建议自己配置一个webapp:
    编辑D:\Webservers\Apache Tomcat 4.0\conf\server.xml
    找到有Context的地方,插入:
      <!--  Add by Fuchj 2003-02-26  for test one demo including workflow --> 
      <Context path="/dreambike" docBase="dreambike" debug="0" privileged="true" /> 
    其中path是http访问的路径如上例为:http://localhost:8080/dreambike
    docBase是程序存放的路径
    重启动tomcat
      

  7.   

    我是在d:\java\tomcat\webapps下新建了一个目录zhouzm,test.jsp就放在\zhouzm下,javaBean放在D:\JAVA\TOMCAT\CLASSES下,并且我在server.xml下配置了<Context path="/zhouzm" docBase="zhouzm" debug="0" privileged="true" />,可还是不能读文件。
    我的javabean如下:
    package database;import java.sql.*;public class OPDB {
        private String sDBDriver="sun.jdbc.odbc.JdbcOdbcDriver";
        private String sDBConn="jdbc:odbc:bbs";
        private Connection conn=null;
        private ResultSet rs=null;
        private Statement stmt=null;    public OPDB() {
          try{
            Class.forName(sDBDriver);
          }
          catch(Exception e){
            e.printStackTrace();
          }
        }    public ResultSet select(String sql){
          try{
            conn=DriverManager.getConnection(sDBConn, "system", "manager");
            stmt=conn.createStatement();
            rs=stmt.executeQuery(sql);
          }
          catch(SQLException e){
            e.printStackTrace();
          }
          return rs;
        }    public void update(String sql){
          try{
            conn=DriverManager.getConnection(sDBConn, "sa", "");
            stmt=conn.createStatement();
            stmt.executeUpdate(sql);
          }
          catch(SQLException e){
            e.printStackTrace();
          }
        }    public void Close(){
          try{
            if(rs!=null){
              rs.close();
            }
            if(stmt!=null){
              stmt.close();
            }
            if(conn!=null){
              conn.close();
            }
          }
          catch(Exception e){
            e.printStackTrace();
          }
        }
    }
      

  8.   

    不好意思贴错了!
    package testcounter;/**
     * <p>Title: </p>
     * <p>Description: </p>
     * <p>Copyright: Copyright (c) 2003</p>
     * <p>Company: riozn</p>
     * @zhouzm
     * @version 1.0
     */import java.io.*;public class counter {
      private String currentRecord=null;
      private BufferedReader file=null;
      private String path=null;  public counter() {  }  public String readFile(String fileName){
        path=fileName;
        String returnStr=null;
        try{
          file=new BufferedReader(new FileReader(path));
        }
        catch(FileNotFoundException e1){
          System.out.println("文件没有找到!");
          return null;
        }
        try{
          currentRecord=file.readLine();
        }
        catch(IOException e){
          System.out.println("读取数据错误.");
          return null;
        }
        if (currentRecord==null)
          returnStr="100000";
        else{
          returnStr=currentRecord;
        }
        return returnStr;
      }  public void writeFile(String fileName, String counter) throws FileNotFoundException{
        path=fileName;
        int writeStr=Integer.parseInt(counter)+1;
        try{
          PrintWriter pw=new PrintWriter(new FileOutputStream(path));
          pw.println(writeStr);
          pw.close();
        }
        catch(IOException e){
          System.out.println("写入文件错误"+e.getMessage());
        }
      }
    }