2012-08-15 64 views
0

嘿,我写了一个JSP从文件系统需要一个txt文件,需要通过line.But线显示它由于某种原因,其没有得到displayed.Thanks提前TXT文件

<html> 
<head> 
<title>DrAssist Reporting Tool</title> 
</head> 
<body> 
    <p>Welcome to the DrAssist Reporting Tool</p> 
    <p>Suite Report Information</p> 
    <h1>Suite : ${suite}</h1> 
    <h1>NoOfTests:${noOfTests}</h1> 
    <h1>Test Name:${TestName}</h1> 
    <h1>FitnesseRestURL:${FitnesseRestURL}</h1> 
    <h1>Rights:${rights}</h1> 
    <h1>Wrongs:${wrongs}</h1> 
    <h1>Ignores:${ignores}</h1> 
    <h1>Exceptions:${exceptions}</h1> 
    <h1>TimeinMilliseconds:${timeOfExecution}</h1> 
    <%@ include file="Test1.html" %> 
    <%@ page language="java" import="java.net.Authenticator,java.net.PasswordAuthentication,java.io.BufferedReader,java.net.*,java.io.*" contentType="text/html; charset=ISO-8859-1" 
    pageEncoding="ISO-8859-1"%> 
    <% 
    BufferedReader input = new BufferedReader(new FileReader("C:\\DrAssistQA\\reports\\120703-100125\\log-120703-100125.txt")); 
    String line = ""; 
    while ((line = input.readLine()) != null) { 
    System.out.println(line); 
} 
    out.flush(); 
    input.close(); 
%> 


<%=line%> 



</body> 
</html> 
+0

Ewewewew。将文件读入servlet或实用程序类中的字符串并使用JSP EL显示该字符串非常简洁。 – 2012-08-15 20:36:01

回答

0

使用out.println而不是System.out.printlnout是一个在JSP中为浏览器输出流操作自动创建的变量。另外不要忘记HTML换行符。

while ((line = input.readLine()) != null) { 
    out.println(line + "<BR>"); 
} 
+0

我做到了,但没有工作。要清楚我已经在.txt文件之前显示了一个.html文件。这是一个问题。我不这么认为,但仍然要求并且.txt需要在Web-INF中/ pages目录。 – 2012-08-15 20:24:53

+0

预先显示html文件没有问题。 – Reimeus 2012-08-15 20:28:08

+0

那么可能是什么问题。 – 2012-08-15 20:29:40

0

这是你的系统而不是浏览器窗口。改为尝试response.write()