• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to save jsp report to the text file

 
Thanikachalam Jayaprakash
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
I have generated a JSP Report and I need to save the report into the text file format. I mean the JSP Report output should be painted on text file.
Your suggestion kindly aprreciated.

Regards,
Prakash
 
yoga babu
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hai,

I am also facing the same problem.pls ,if u find any solution for saving jsp page as text file then forward ur suggesstions and sample coding..

Thank you

Regards
Babu
 
Richard Green
Ranch Hand
Posts: 536
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I assume that you would have a Servlet that backs up this JSP page. You could make the servlet print out a text file (or a csv file) with the data you want.
 
sundaramoorthi thangavel
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
use the follwing code in your jsp.

<%
response.setContentType("text/plain");
response.setHeader("content-disposition","attachment; filename=temp.txt");
%>
 
yoga babu
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hai,
thanks for your time.actually i inserted ur coding in my program but file is not having any data.pls check my previous coding,and tell me where i have do modification and where i have to insert ur codings..pls help me.


<%
FileOutputStream outfile;
PrintStream p,p1;
outfile= new FileOutputStream("d:\\temp\\error1.txt");
outfile= new FileOutputStream(filename);
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbcdbc:pro","pro","pro");
Statement st=con.createStatement();
ResultSet rs=st.executeQuery("select * from CSG where Module='7613-slot6' ");
p = new PrintStream(outfile);
p.println(" Module DateTime Allocated Memory Available Memory

OsStaic Memory");

while(rs.next())
{

String date=rs.getString(1);
String time=rs.getString(2);
String availablememory=rs.getString(3);
String allocatedmemory=rs.getString(4);
String osstatic=rs.getString(5);

p.println(" "+date+" "+time+" "+availablememory+"

"+allocatedmemory+" "+osstatic+" ");
}
%>

thanks a lot

Regards
Babu
 
Ernesto Elias-Nieland
Ranch Hand
Posts: 53
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!

You should tell us why your code is not working and what error message you receive when you execute the JSP page. But as a first guess I think you should close your Streams by calling p.close()and outfile.close(). And I would delete the PrintStream p1 variable because it is never used.

Sincerly,
Ernie
 
yoga babu
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

In My coding i m not getting any error.but i want to save my data according to user wish.But in my program i mention particular name for the file and location.
For that i add this coomand ,then
response.setContentType("text/plain");
response.setHeader("Content-Disposition", "attachment;filename=File1.txt");
i m getting plain text file,its not having any data in the corresponding selected location.what i have to do...pls guide me..


Thanks a lot

With Regards
Babu
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic