• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Display the contents of a file on jsp page

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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>
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"shivashankar Mn", please check your private messages for an important administrative matter.
 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Its working ....! Thank you very much
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic