• Post Reply Bookmark Topic Watch Topic
  • New Topic

Display the contents of a file on jsp page

 
shivashankar matam
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have given a my code, when i try to execute it the contents of a file log1.txt is not displayed on jsp page. I find no errors . please let me know the where the problem is :


<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<%!
String fileOutput;
%>

<%@ page
import="java.lang.*"
import="java.util.Scanner"
import="java.io.FileReader"
import="java.net.*"
%>

<%!
class DisplayLog {

void display(){
try {
String fileName;
String s2="c:/example/log1.txt";
StringBuffer buffer = new StringBuffer();

Scanner scan = new Scanner(new FileReader(s2));


String readdata="";
while ((readdata=scan.nextLine())!=null){

buffer.append(readdata).append('\n');
}
fileOutput = buffer.toString();
}catch(Exception e)
{
}
}
}
%>



<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body bgcolor="blue">

<tr>
<CENTER> <img src="images/logo.jpg" width="50" height="60" alt="logo"/><h1>Project</h1> </CENTER>
</tr>
<center><h2>Debug Mode</h2></center>
<HR WIDTH="100%" SIZE="3" NOSHADE>
<FORM METHOD=post ACTION="/cgi-bin/example.cgi">
<!-- <textarea name="txtAreaLog" cols="30" rows="20" readonly="readonly" title="log area"> </textarea> -->
<textarea rows="20" cols="62" readonly =" readonly" WRAP="off"><%= (fileOutput != null) ? fileOutput : "" %></textarea>
</FORM>

<FORM METHOD=post ACTION="/cgi-bin/example.cgi">
Enter file name:<BR>
<INPUT type="text" size="10" maxlength="30">
<INPUT type="Submit" VALUE="Submit">
</FORM>
<div align="right">[ <A href="logout.jsp" style=""><font style="font-family:verdana; font-size:70%;" color="blue"><b>L</b>ogout</font></A> ]</div>
</body>
</html>
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65524
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"shivashankar Mn", please check your private messages for an important administrative matter.
 
Lei Guoguo
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the method DisplayLog.display() in your jsp is not invoke?
 
Lei Guoguo
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you can use like this:
of course, this codes also need to improve

in class DisplayLog:


in the jsp page:
 
shivashankar matam
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Its working ....! Thank you very much
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!