Welcome to Dream.In.Code
Become an Expert!

Join 149,527 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,474 people online right now. Registration is fast and FREE... Join Now!




How to open and retrive data from text file(.txt) using JSP

 
Reply to this topicStart new topic

How to open and retrive data from text file(.txt) using JSP, can't find any solution about it.

una_noche
26 Jun, 2007 - 06:28 PM
Post #1

New D.I.C Head
*

Joined: 26 Jun, 2007
Posts: 2


My Contributions
i have some process where user want some data (text file .txt) from somewhere for example from D:\smartcard\rs55566.txt. After user have that file the user can choose whether he want to save the text file or display it as a text file. Could anyone here give some idea or code example about this? i have search many times throuh web but i did'tn get any solution. Really need help here.
Thanks...~

This post has been edited by una_noche: 26 Jun, 2007 - 07:32 PM
User is offlineProfile CardPM
+Quote Post

1lacca
RE: How To Open And Retrive Data From Text File(.txt) Using JSP
27 Jun, 2007 - 01:57 AM
Post #2

code.rascal
Group Icon

Joined: 11 Aug, 2005
Posts: 3,822



Thanked: 12 times
My Contributions
It was not totally clear for me: is your text file on the server?
File access from JSPs is possible, but not encouraged.
You can simply open it from a scriplet in the same way as in a Java SE applicaiton. Sending it backto the user is also possible, the browser's behaviour is defined by the http headers sent in the response. (look for the Content-Disposition header)

If the file is on the client's computer, then things are different...

This post has been edited by 1lacca: 27 Jun, 2007 - 01:57 AM
User is offlineProfile CardPM
+Quote Post

una_noche
RE: How To Open And Retrive Data From Text File(.txt) Using JSP
27 Jun, 2007 - 04:28 PM
Post #3

New D.I.C Head
*

Joined: 26 Jun, 2007
Posts: 2


My Contributions
The file is on the server, not in the client's computer.
Here i have some coding but not really sure whether i can use it for the process or not.
Could anyone here take a look for a while??

CODE

<%
// fetch the file
String filename = "companySecret.txt";
String filepath = "C:\\";

response.setContentType("application/octet-stream");
response.setHeader("Content-Disposition", "attachment; filename=\"" + filename + '"');

java.io.FileInputStream fileInputStream = new java.io.FileInputStream(filepath + filename);

int i;
while ((i=fileInputStream.read()) != -1)
{
    out.write(i);
}

fileInputStream.close();
out.close();
%>


This post has been edited by una_noche: 27 Jun, 2007 - 04:44 PM
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/7/09 08:51PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month