473,406 Members | 2,343 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Reading .js file into JSP code

Anyone out there know of an easy way to fill a Java ArrayList in a JSP from
an
array of strings held in a external JavaScript file? We need to load up a
large number of strings into the page and manipulate with JSP, and feel that
the best way is for the users to have the bulk of the text 'cached' on their
machine in a .js file rather than read from a database every time they
access. The strings will rarely change.

If not, any other better suggestions for cutting the speed of download?

Thanks
Iain

--

__________________________________________________ _________
Dr Iain Downie
Web Software Developer, British Trust for Ornithology, The Nunnery,
Thetford, Norfolk IP24 2PU, UK ® Charity No. 216652
Tel: +44 (0)1842 750050, fax: +44 (0)1842 750030 Ia*********@bto.org

BirdWeb Gateway: http://www.bto.org/birdweb
Jul 23 '05 #1
7 2961
On Tue, 29 Jun 2004 15:17:25 +0100, Iain Downie wrote:
Anyone out there know of an easy way to fill a Java ArrayList
in a JSP ...
On the server. Not so much the 'easy' way,
as the 'only' way.
...from an array of strings held in a external JavaScript file?


If that JS file was on the server,
you could load it and parse it for
the strings, but the *easy* way is
to define the strings as Java Strings
in the JSP, or define the ArrayList
itself in the JSP.

*Whatever* you are trying to achieve,
you are going about it the completely
wrong way.

--
Andrew Thompson
http://www.PhySci.org/ Open-source software suite
http://www.PhySci.org/codes/ Web & IT Help
http://www.1point1C.org/ Science & Technology
Jul 23 '05 #2
After quite a bit of searching, I'm inclined to agree that this is pretty
much impossible, as JavaScript is client and JSP server-side. What I am
trying to *achieve* is get the strings in a file that is as fast as possible
to use, and I thought having that cached on the clients machine would be
best - now know otherwise.

I think I'll have to follow your suggestion and find some way to predefine
the list of strings in JSP, but without constant calls to the database.

Thanks
Iain

"Andrew Thompson" <Se********@www.invalid> wrote in message
news:8t*****************************@40tude.net...
On Tue, 29 Jun 2004 15:17:25 +0100, Iain Downie wrote:
Anyone out there know of an easy way to fill a Java ArrayList
in a JSP ...


On the server. Not so much the 'easy' way,
as the 'only' way.
...from an array of strings held in a external JavaScript file?


If that JS file was on the server,
you could load it and parse it for
the strings, but the *easy* way is
to define the strings as Java Strings
in the JSP, or define the ArrayList
itself in the JSP.

*Whatever* you are trying to achieve,
you are going about it the completely
wrong way.

--
Andrew Thompson
http://www.PhySci.org/ Open-source software suite
http://www.PhySci.org/codes/ Web & IT Help
http://www.1point1C.org/ Science & Technology

Jul 23 '05 #3
Iain Downie wrote:
Anyone out there know of an easy way to fill a Java ArrayList in a JSP from
an
array of strings held in a external JavaScript file? We need to load up a
large number of strings into the page and manipulate with JSP, and feel that
the best way is for the users to have the bulk of the text 'cached' on their
machine in a .js file rather than read from a database every time they
access. The strings will rarely change.

If not, any other better suggestions for cutting the speed of download?

Thanks
Iain


Of course this is possible. Given the understanding that a JSP generates HTML
dynamically, it isn't too much of a stretch to understand it can generate
Javascript dynamically as well. So your starting point is:

<script type="text/javascript"
src="somethingThatMakesAJavascriptArray.jsp"></script>

Then somethingThatMakesAJavascriptArray.jsp would read the database and generate
code that resembles:

var yourArray = [
"value1",
"value2",
"value3"
// etc
];

Doing this in server-side Javascript would be something like:

<%
// do the database retrieval into resultSet here complete
// with error checking; if resultSet is properly populated
// then proceed with the code below
Response.write('var yourArray = [\n');
var lastIndex = resultSet.rows - 1;
for (var i = 0; i < resultSet.rows; i++) {
resultSet.cursor = i;
Response.write('\t"' + resultSet.theColumn + '"');
if (i < lastIndex) {
Response.write(',');
}
}
Response.write('];');
%>

But depending on the amount of data involved, downloading this huge array to the
client might not be such a wise idea. Not to mention once the data is "cached"
in a client-side Javascript array, it can't be manipulated by JSP, it has to be
managed by client-side Javascript, something that might be problematic if you're
supporting multiple browsers.

--
| Grant Wagner <gw*****@agricoreunited.com>

* Client-side Javascript and Netscape 4 DOM Reference available at:
*
http://devedge.netscape.com/library/...ce/frames.html

* Internet Explorer DOM Reference available at:
*
http://msdn.microsoft.com/workshop/a...ence_entry.asp

* Netscape 6/7 DOM Reference available at:
* http://www.mozilla.org/docs/dom/domref/
* Tips for upgrading JavaScript for Netscape 7 / Mozilla
* http://www.mozilla.org/docs/web-deve...upgrade_2.html
Jul 23 '05 #4
In article <cb*******************@news.demon.co.uk>, ia*********@bto.org
enlightened us with...
After quite a bit of searching, I'm inclined to agree that this is pretty
much impossible, as JavaScript is client and JSP server-side. What I am
trying to *achieve* is get the strings in a file that is as fast as possible
to use, and I thought having that cached on the clients machine would be
best - now know otherwise.

I think I'll have to follow your suggestion and find some way to predefine
the list of strings in JSP, but without constant calls to the database.


Why don't you just use an include file?
Same thing as the JS file concept, but all on the server.
JSP has an include directive.

--
--
~kaeli~
Going to church doesn't make you a Christian any more than
standing in a garage makes you a car.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

Jul 23 '05 #5

"kaeli" <ti******@NOSPAM.comcast.net> wrote in message
news:MP************************@nntp.lucent.com...
Why don't you just use an include file?
Same thing as the JS file concept, but all on the server.
JSP has an include directive.


I thought about that, and yes it is possible, but what advantages in
download speed would there be? The original idea was the huge array of
strings would have been held on the clients machine and thus not need as
much download. An include file would always have to be recalled when the JSP
is turned into HTML. The only advantage I can see with includes (in this
case) would be easier coding and a single instance that I can update when
required.

Thanks
Iain
Jul 23 '05 #6
On Wed, 30 Jun 2004 08:41:56 +0100, Iain Downie wrote:
"kaeli" <ti******@NOSPAM.comcast.net> wrote in message

...
Why don't you just use an include file?
Same thing as the JS file concept, but all on the server.
JSP has an include directive.


I thought about that, and yes it is possible, but what advantages in
download speed would there be? The original idea was the huge array of
strings would have been held on the clients machine and thus not need as
much download.


We have now determined that what you wish to
achieve cannot be done with JS, so this thread
should be continued elsewhere.

I will give you a parting thought though.
A signed Java applet can store data on the
client for quick access..

If you choose to use an applet, I suggest you
make a 'follow-up' to this post, but direct
it straight to c.l.java.programmer.

HTH

--
Andrew Thompson
http://www.PhySci.org/ Open-source software suite
http://www.PhySci.org/codes/ Web & IT Help
http://www.1point1C.org/ Science & Technology
Jul 23 '05 #7
Iain Downie wrote:
After quite a bit of searching, I'm inclined to agree that this is pretty
much impossible, as JavaScript is client [...]-side. [...]


No, J(ava)Script is a script language. It can be used both client-
and server-side, provided that you have an appropriate server.
PointedEars
Jul 23 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Xah Lee | last post by:
# -*- coding: utf-8 -*- # Python # to open a file and write to file # do f=open('xfile.txt','w') # this creates a file "object" and name it f. # the second argument of open can be
1
by: fabrice | last post by:
Hello, I've got trouble reading a text file (event viewer dump) by using the getline() function... After 200 - 300 lines that are read correctly, it suddenly stops reading the rest of the...
8
by: Phil Slater | last post by:
I'm trying to process a collection of text files, reading word by word. The program run hangs whenever it encounters a word with an accented letter (like rôle or passé) - ie something that's not a...
19
by: Lionel B | last post by:
Greetings, I need to read (unformatted text) from stdin up to EOF into a char buffer; of course I cannot allocate my buffer until I know how much text is available, and I do not know how much...
4
by: dale zhang | last post by:
Hi, I am trying to save and read an image from MS Access DB based on the following article: http://www.vbdotnetheaven.com/Code/Sept2003/2175.asp Right now, I saved images without any...
1
by: Need Helps | last post by:
Hello. I'm writing an application that writes to a file a month, day, year, number of comments, then some strings for the comments. So the format for each record would look like:...
6
by: arne.muller | last post by:
Hello, I've come across some problems reading strucutres from binary files. Basically I've some strutures typedef struct { int i; double x; int n; double *mz;
2
by: GeoUK | last post by:
Hi All, New member here with a bit of problem. I have read the FAQ's and searched text books but still cannot solve the problem that I have. As part of a course I am doing at University I had...
13
by: swetha | last post by:
HI Every1, I have a problem in reading a binary file. Actually i want a C program which reads in the data from a file which is in binary format and i want to update values in it. The file...
2
by: Derik | last post by:
I've got a XML file I read using a file_get_contents and turn into a simpleXML node every time index.php loads. I suspect this is causing a noticeable lag in my page-execution time. (Or the...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.