Click to See Complete Forum and Search --> : reading file from server


webtekie
04-29-2003, 04:28 PM
Hello,

I have JSP page and I need to read contents of the file located on the server into a JavaScript variable. Any suggestions on how can I accomplish this?

thanks,
webtekie

khalidali63
04-29-2003, 05:36 PM
The appropriate forum for this would be

http://forum.java.sun.com/forum.jsp?forum=45
Now to your question .

First jsp is executed on web server and javascript is executed on client side,so there is no direct link.However you can probably get by this by reading a file put the required data in a string put that string in javascript variable.
May be some thing like this

suppose from the jsp code you create a variable
String line="";
line has some data read from the file.Now assign this value to js variable
<script type="text/javascript">
var fromJsp = "<%=line %>";
</script>

Hope this helps

viravan
04-29-2003, 09:33 PM
Hello there:

Look at what I've found.... some script that I fooled around with a long while back. Decided to put it up on my web site and see if it still works. Guess what? This old horse still runs like a champ (both on IE6 and NN7):

http://home.attbi.com/~aokabc/JS/ReadTxtFile.htm

Check it out!

:)

V.V.