#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    6
    Rep Power
    0

    Using a JAR of JScript files with JSP


    Hi,
    Any one knows if it is possible to use a JAR file that contain some ".js" files to be called from a JSP file.

    I am running WebSphere 4.0.3 on WinXP

    Help....!!?
  2. #2
  3. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    6
    Rep Power
    0
    I've tried to ask HTML guys, but no one helped, and most of them recomended posting in a Java Forum, so here I am......

    Well it did worked on HTML files.....try this:

    Create 2 .js files, each with different functions inside them, say:

    function test1()
    {
    alert("From test1.js");
    }

    save this as "test1.js", then.....

    function test2()
    {
    alert("From test2.js");
    }

    save this as "test2.js"

    now take the 2 files and zip them into this file name "jscripts.jar"

    Create an HTML file and add into it:

    <script archive="jscripts.jar" src="test1.js" language="JavaScript"></script>
    <script archive="jscripts.jar" src="test2.js" language="JavaScript"></script>
    <input type="Button" value="Test JAR" onclick="test1();test2()">

    You will find that the Button will call the 2 functions from the JAR file....kool, right?
    The problem is that this method won't work when run on a Server, I tried many paths for the JAR file but it didn't work

    If any one found a way, Please Mail Me.......

    Thanx guys
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    78
    Rep Power
    12
    I am using Websphere 4 as well.

    What is the relative web path from the page with the button to the jar file?

    example:
    if the pages url is...
    www.somehost.com/myapp/buttonpage.html

    and the jar is located at...
    www.somehost.com/myapp/javascript/jscripts.jar

    then the src attribute path should be...
    src="./javascript/jscripts.jar"

    I'm not sure if the './' is neccassary, but I always use it and Websphere seems not to mind.
  6. #4
  7. I played Richard the Third
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2003
    Location
    Den Haag, Netherlands
    Posts
    122
    Rep Power
    12
    I think it is neccesary. At least the "/". Usually i try different variations "./","/" etc, until Webshere understands what I'm trying to tell it.

    shouldn't your *.jar files be located somewhere in the WEB-INF directory ?
    Now is the winter of our discontent made glorious summer by this son of York.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    78
    Rep Power
    12
    Targaz, he isn't using the .jars as a class archive he is using them as a javascript archive. You are correct that you would want them in the WEB-INF if they are used as a class archive.

    I usually leave my js files in a js directory at the root of the web app unzipped, not sure why some one would want to do zip them together. I hate when people ask me "Why are you trying to do that?" so I figured he had his reasons.

    Sherif, the other thing I thought of was that it may be the mime types that are screwing you up. The server might not like sending jar files as an archive to the web browser. You might want to try a zip file instead.
  10. #6
  11. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    6
    Rep Power
    0
    Ok, thanx guys but the suggestions did not work with me; can I explain in detail what I do........

    The JAR & HTML Files are located on my HDD at :
    D:/Project/ClientA/webApplication/

    I call it (locally) from the browser like this:
    http://localhost:8080/ClientA/test.htm

    I've attached the files (1kb Zip) for anyone to try it out....
    If you just call the test.htm file from the Browser, it will work, but from the Server, it won't.

    Sm00ve, I do have my reasons, the client I am writting code for, is in some place where ppl use dial-up with 3kb/sec MAX, and I got 100kb pages with 25kb JScript files, thus compressing them into a 5kb JAR file will help a lot....

    Guys, if any one can get it to work it will really help......all of us (or most of us, I guess)......

    Thanx
    Attached Files
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    78
    Rep Power
    12
    Sherif,
    I found the following info segiment here...
    http://developer.irt.org/script/1356.htm

    I use this site for javascirpt reference and have found it somewhat useful.

    Netscape Navigator and Internet Explorer both claim to support *.jar files, but only Netscape Navigator seems to work with them.

    Place bar.js inside foo.jar and then use:

    <script archive="foo.jar" src="bar.js"></script>


    I'm sorry but it doesn't look like you will be able to have this work on IE.

    However, I was curious do your pages need ALL of the functions that are in each page or just some of them?
    One thing I do with my .js files is to break up each page into a logical grouping (i.e. I have 1 js that has the most common functions, and then I have a js file that is specific to a particular page that contains functions only used for that page). This way I am only ever includeing 2 or three SMALL js files at a time.

    Just a thought.
    Last edited by Sm00ve; July 16th, 2003 at 08:49 AM.

IMN logo majestic logo threadwatch logo seochat tools logo