File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes how to save jsp report to the text file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "how to save jsp report to the text file" Watch "how to save jsp report to the text file" New topic
Author

how to save jsp report to the text file

Thanikachalam Jayaprakash
Greenhorn

Joined: Mar 22, 2006
Posts: 6
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


Thanks and Regards!
yoga babu
Greenhorn

Joined: Jul 18, 2006
Posts: 17
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

Joined: Aug 25, 2005
Posts: 536
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.


MCSD, SCJP, SCWCD, SCBCD, SCJD (in progress - URLybird 1.2.1)
sundaramoorthi thangavel
Greenhorn

Joined: Jul 18, 2006
Posts: 6
use the follwing code in your jsp.

<%
response.setContentType("text/plain");
response.setHeader("content-disposition","attachment; filename=temp.txt");
%>
yoga babu
Greenhorn

Joined: Jul 18, 2006
Posts: 17
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

Joined: Sep 01, 2005
Posts: 53

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


0x2B | ~0x2B
SCJD, SCJP 1.5, SCJP 1.4, SCBCD 1.3, SCWCD 1.4, SCJA, IBM Test 150, 142, 700, 701, Oracle Test 1Z0-51
yoga babu
Greenhorn

Joined: Jul 18, 2006
Posts: 17
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
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: how to save jsp report to the text file