This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Struts and the fly likes Outputting to .txt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Outputting to .txt" Watch "Outputting to .txt" New topic
Author

Outputting to .txt

Yogendra Joshi
Ranch Hand

Joined: Apr 04, 2006
Posts: 213
Hello Ranchers ,

I have a page which has a Table which has details like name , password , address , telephone number etc...

Now this is displayed from the database nicely as i want to. Now i have a button saying EXPORT to .txt , Whatever data it shows on the Jsp i.e name,, password , address , telephone number etc on click of that button should popup an option to the user giving him / her an option to save the data as .txt file. I have tried response.setContentType(text/plain) and setting the header to .txt button , the file which is opening is outputting the source of the html page then the output which i am desiring i.e name , username etc.

Can someone please show me the light on how this can be achieved. Previously it was application/vnd.ms-excel and it used to save in excel , but now the users need it into a .txt rather then .xls.

Any help is much appreciated.

Thanks in advance.

Yogendra N Joshi


Meri Zindagi Hain Tab Tak.. Jab Tak Tera Sahara.... Har Taraf Tu Hi Tu Hain SAI Tera Hi Hain Nazara.....
Dom Lassy
Ranch Hand

Joined: May 05, 2006
Posts: 181
In your action:
Yogendra Joshi
Ranch Hand

Joined: Apr 04, 2006
Posts: 213
Hello thanks for the code, I have tried to put it.

It giving an exception saying method getFileByteArrayOutputStream(); cannot be resolved to a type. I have seen the API for ByteArrayOutputStream but didn't get any fruits out of it.

The Current code is :



For the extension which we are using right now . i.e doc , its coming very perfectly. Also if the extension is .xls then its coming fine. Only for .txt it is giving problems. Can you please give us more idea on this ?

Thanks again.
Yogendra
[ November 03, 2006: Message edited by: Yogendra Joshi ]
Dom Lassy
Ranch Hand

Joined: May 05, 2006
Posts: 181
getFileByteArrayOutputStream() is method I made up.

Replace it with a ByteArrayOutputStream of the txt file you want to display.
Yogendra Joshi
Ranch Hand

Joined: Apr 04, 2006
Posts: 213
Hey Dom ,

Thanks for the immediate reply.

I think the getFileByteArrayOutputStream which you made up for you would work for me as well.. Can you post that too ?

Thanks

Yogendra
Dom Lassy
Ranch Hand

Joined: May 05, 2006
Posts: 181
I just made up the method name.

If you tell me where you're getting the text file from (disk, string, etc..) I can help you convert it to an output stream.
Dom Lassy
Ranch Hand

Joined: May 05, 2006
Posts: 181
If you have a String, here is how to get an output stream:



I'm not sure if this will work because I haven't tested it or tried to complie it, but it shouldn't be too far off.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Outputting to .txt
 
Similar Threads
Read Some 10,000 Files
hibernate's real world value
File download Problem
How do i save a file that has been generated using JSP in excel format .
Upload Data in Excel file