在java中读取陷入循环的文本文件

在java中读取陷入循环的文本文件,java,jsp,Java,Jsp,我正在创建一个程序,从存储在服务器上的文本文件中读取数据。我能够读取文件并在控制台中以我想要的方式获得结果,但是当我尝试在网页上显示它们时,我得到的结果完全不同。我在控制台上得到的结果是 Log File Path: the path is here Input Directory: the input directory Results Directory: the results directory 在我的网页上 Log File Path: the path is here Log Fi

我正在创建一个程序,从存储在服务器上的文本文件中读取数据。我能够读取文件并在控制台中以我想要的方式获得结果,但是当我尝试在网页上显示它们时,我得到的结果完全不同。我在控制台上得到的结果是

Log File Path: the path is here
Input Directory: the input directory
Results Directory: the results directory
在我的网页上

Log File Path: the path is here
Log File Path: the path is here
Log File Path: the path is here
Input Directory: the input directory
Input Directory: the input directory
Input Directory: the input directory
Results Directory: the results directory
Results Directory: the results directory
Results Directory: the results directory
下面是我的代码的样子:

  <%

        File file = new File("the file path");
        BufferedReader br = new BufferedReader(new FileReader(file));

        String st;


        while((st = br.readLine()) !=null){
            System.out.println(st);

        %>
        <form action="performMagic('<%=mr.getKey()%>')" method="post"
            enctype="multipart/form-data">
            Log File Path:<%=st%><br>
            Input Directory:<%=st %><br>
            Results Directory:<%=st %><br>
        </form>
        <br>

    </ul>

    <%

        }
        br.close();
    %>

日志文件路径:
输入目录:
结果目录:


这与我的while循环有关,我不知道问题出在哪里。

你的“br.close();”语句出现在你的while循环中。

对不起,我的代码有误。最初,
br.close()
位于循环外部,而不是内部。在循环中,它只显示文本第n次中的第一行。我明白了。这个代码段前面是什么?您确定在您呈现的部件之前或之后执行的任何代码都不会影响您的输出吗?