Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Outputting to .txt

 
Yogendra Joshi
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Dom Lassy
Ranch Hand
Posts: 181
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In your action:
 
Yogendra Joshi
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 181
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
getFileByteArrayOutputStream() is method I made up.

Replace it with a ByteArrayOutputStream of the txt file you want to display.
 
Yogendra Joshi
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 181
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 181
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic