Reading a text file in VBScript on a JSP Page

I have a JSP page, and I'd like to open a file. I've ben told this is possible using VB Script inside different tags? Has nyone experience with this? If so what would I need to do in VB script to achieve this, need to open and read a tab delimited file?
thanks
skellycAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

objectsCommented:
why don't u just use java?
0
CodingExpertsCommented:
You want to open a client side file and display the contents/upload it. What exactly do u want to do ??

-CE
0
skellycAuthor Commented:
yep its a client side file which I want to open. then read the contents and upload a string to a workerbean.
re: using java. I can uplodad the whole file using a servlet and try and read data in the servlet but ..
this is specifically Word and Excel files though,  I imagine this will be easier in VB Script?

0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

CodingExpertsCommented:
Basically, if you are looking for an utility for file upload u can see

http://jakarta.apache.org/commons/fileupload/using.html

CE
0
skellycAuthor Commented:
thanks I used the DiskFileUpload apache class to upload files, in a servlet etc, but therea a number of issues with doing this, I'm coming up against security and application deployment problems when saving files to the unix directory that are not eay to resolve straight away. I was rather looking therefore for a client side solution to rather parse a file locally and set up a string I can pass easily to a bean etc.....
apologies for the confusion;
0
CodingExpertsCommented:
You can try and set the content type

http://www.utoronto.ca/webdocs/HTMLdocs/Book/Book-3ed/appb/mimetype.html

you can use ..

response.setContentType("application/msword");
response.setHeader("Content-disposition","inline; filename=" + "report.doc");


-CE
0
skellycAuthor Commented:
sorry dont know vb at all,
are there any code snippets/prewritten functions etc I can access?
On click event, Need to open a doc, parse contents the contents into a string etc..
Can I just set up new script tags with vb script on a jsp etc?

thanks
c,.
0
sudhakar_koundinyaCommented:
This will show a messagebox on load of html body

<html>


<Script Language=VBScript>

sub readFile
on error resume next
Set objFSO = CreateObject("Scripting.FileSystemObject")

vText = ""
'input text file
Set objTF = objFSO.OpenTextFile("c:\a.csv")

    do while not objTF.AtEndofStream
   
        for i = 1 to 4
            vText = vText & objTF.Readline
        next 'i

    loop
msgbox vText

Set objTF = nothing
Set objFSO = nothing

end sub
</script>

<body onLoad=readFile()>
</body>

</html>
0
sudhakar_koundinyaCommented:
small correction

don't need to have inner for loop

<html>
<Script Language=VBScript>
sub readFile
on error resume next

Set objFSO = CreateObject("Scripting.FileSystemObject")
vText = ""
'input text file
Set objTF = objFSO.OpenTextFile("c:\test.txt")

    do while not objTF.AtEndofStream
           vText = vText & objTF.Readline
   loop
msgbox vText

Set objTF = nothing
Set objFSO = nothing

 
end sub
</script>
<body onLoad=readFile()>
</body>

</html>
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
sudhakar_koundinyaCommented:
but note that

Reading the files at client side is limited to Internet Explorer only

Regards
Sudhakar
0
skellycAuthor Commented:
great, this does the job. I'd also like to ask how I can use the input type of file (button) to get a filepath dynamically and pass this to the function....
0
sudhakar_koundinyaCommented:
thanks for thne points

here is the sample as per ur requirements

<html>
<Script Language=VBScript>

function readFile (file)
on error resume next
Set objFSO = CreateObject("Scripting.FileSystemObject")
vText = ""
'input text file
Set objTF = objFSO.OpenTextFile(file)

    do while not objTF.AtEndofStream
     vText = vText & objTF.Readline
    loop

Set objTF = nothing
Set objFSO = nothing
readFile=vText
end function

sub read_OnClick()
testform.fileholder.value=readfile( testform.testfile.value)
end sub

</script>

<body>
<form name=testform>
<P>
<input type=file name=testfile >&nbsp;&nbsp; <INPUT type=button value=read name=read></P>
<P> <INPUT style="WIDTH:
 511px; HEIGHT: 173px" size=1443 name=fileholder rows="100"
cols="100" readonly width="44" vspace=44>
</P>
</form>
</body>

</html>
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JSP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.