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 creating a text file from JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "creating a text file from JSP" Watch "creating a text file from JSP" New topic
Author

creating a text file from JSP

evan theon
Ranch Hand

Joined: Feb 16, 2005
Posts: 39
i have read the psoting concerning my issue but it seems nothing is exactly what i need. i need to create a text file based on the html page seen on the user's screen (the HTML page is generated by the JSP page, i mean it is originally a JSP page but it appears as a HTML page on the user's screen right?) and save it in the user's computer can it be done and how?

please help........

thanks
Satish Chilukuri
Ranch Hand

Joined: Jun 23, 2005
Posts: 266
Once the jsp page is rendered to the user, it is like any other web page. You can save the page through the browser. Or is it that you want to do capture the rendered page at the server side and then save it in the user's computer?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61450
    
  67

You cannot write anything to the client system without the user taking action.

You can instruct the user to use View Source to obtain the HTML, or you can use techniques to capture the HTML on the server and provide a link to the user. But you cannot write to the client file system.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61450
    
  67

See this topic.
evan theon
Ranch Hand

Joined: Feb 16, 2005
Posts: 39
>Once the jsp page is rendered to the user, it is like any other web page. You >can save the page through the browser. Or is it that you want to do capture >the rendered page at the server side and then save it in the user's computer?

i am not sure which one is suitable for me, i just want to create a text file from a jsp page, just like creating an excel file from a jsp page using response.setContentType and response.setHeader, can it be done the same way? i've tried to change

response.setContentType("application/vnd.ms-excel");

response.setHeader("Content-disposition","attachment;filename=file1.sxc");


into

response.setContentType("application/vnd.ms-word");
response.setHeader("Content-disposition","attachment;filename=file1.txt");

but i have a text file contained with the HTML source code, what i want is that the text file contains the HTML page that seen on user's screen not the HTML source code

what should i do?
evan theon
Ranch Hand

Joined: Feb 16, 2005
Posts: 39
please help.....i would be very thankful.....
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Originally posted by evan theon:
>Once the jsp page is rendered to the user, it is like any other web page. You >can save the page through the browser. Or is it that you want to do capture >the rendered page at the server side and then save it in the user's computer?

i am not sure which one is suitable for me, i just want to create a text file from a jsp page, just like creating an excel file from a jsp page using response.setContentType and response.setHeader, can it be done the same way? i've tried to change

response.setContentType("application/vnd.ms-excel");

response.setHeader("Content-disposition","attachment;filename=file1.sxc");


into

response.setContentType("application/vnd.ms-word");
response.setHeader("Content-disposition","attachment;filename=file1.txt");

but i have a text file contained with the HTML source code, what i want is that the text file contains the HTML page that seen on user's screen not the HTML source code

what should i do?


It looks like there is a slight misunderstanding here.
Setting the content type to "application/vnd.ms-excel", does not cause the JSP to "create" an Excel page. The page you're creating is exactly the same as it would be with any other content type. All you're doing is sending a header to the browser which suggests that the browser open this file with the application associated with that content type (in this case Excel).
You don't see the HTML markup because Excel is capable of interpreting HTML and presenting it as a spread sheet.

If you instruct the browser to open a document in Word and tell word that this is a text file (text meaning no markup), it's going to render it exactly the way it is written (markup and all).

I think Word can also interpret HTML. I know you can convert a Word doc to HTML from within word (hideous html but that's another topic). Try leaving the content type as you have it but set the file extension to ".html" in the disposition tag.
It might work.

If not, look into Jakarta POI and see if you can create a "REAL" Word document on the server and stream that down to the client.

The truth is, there is no spoon

Also:

please help.....i would be very thankful.....

Before adding another post to a thread that looks like this, you might want to read: Patience Is A Virtue to learn how you may actually be slowing down your answers.
[ September 10, 2005: Message edited by: Ben Souther ]

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
evan theon
Ranch Hand

Joined: Feb 16, 2005
Posts: 39
i'm really sorry for being impatience but it is not my intention to do that....but it is because the deadline is hunting me down...
once again i'm really sorry, but usually this forum gives answer even quicker than i thought, so i assumed you guys were busy so i give some kinda reminder but once again i'm really sorry
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

More importantly, did you understand what I meant when I said that JSP doesn't actually "create" a native format MS-Office file?
evan theon
Ranch Hand

Joined: Feb 16, 2005
Posts: 39
now i understand that JSP doesn't actually "create" a native format MS-Office file...
OK i give up... maybe i should try the Jakarta POI project that you mentioned earlier, but can you give me a brief explanation of what it is, how to used it, how to combine it with JSP? or maybe a good reference would be great.... where should i strat learning about Jakarta POI?

thank you very much for your help....
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Nope,
but I'm sure their documentation could.
http://jakarta.apache.org/poi/
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: creating a text file from JSP