Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: server to browser transference

  1. #1
    Junior Member
    Join Date
    May 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default server to browser transference

    hi everybody

    i need for mi hobbie web app a transference between a java array and a javascript array. this is what i have tried to accomplish but it doesnt seem to work well:

    <script type="text/javascript">
    var arrayJS=new array();
    <% String[] javaArray=(String[])request.getAttribute("names");%>
    arrayJS=<%=javaArray%>;
    for(var i=0;i<arrayJS.length;i++)
    //data processing

    any help would be so much appreciated


  2. #2
    Member
    Join Date
    Apr 2012
    Location
    Superior, CO, USA
    Posts
    80
    Thanks
    0
    Thanked 14 Times in 14 Posts

    Default Re: server to browser transference

    As you've seen this isn't the way to go about it. How is the request parameter "names" formatted? Based on your code it sounds like it would be something like

    names=Bob&names=Sue&names=Barf

    is this correct? That's kind of a weird URL but it can be dealt with entirely in JavaScript:

    var arrayJS=new array();
    var searchString = document.location.search;
     
    // strip off the leading '?'
    searchString = searchString.substring(1);
     
    var nvPairs = searchString.split("&");
     
    for (i = 0; i < nvPairs.length; i++) {
        var nvPair = nvPairs[i].split("=");
     
        if( nvPair[0] === 'names' ) {
            arrayJS.push( nvPair[1] );
        }
    }

    This code was derived from here.
    Need Java help? Check out the HotJoe Java Help forums!

Similar Threads

  1. [SOLVED] Why doesn't my Applet show up in my browser?
    By SendBorg in forum Java Applets
    Replies: 3
    Last Post: January 29th, 2012, 07:30 AM
  2. How to run Applet with Ms Sql connectivity in browser
    By mayanksmart4 in forum Java Applets
    Replies: 1
    Last Post: November 22nd, 2011, 08:57 AM
  3. HELP! My applet won't run on a web browser....
    By coolidge in forum Java Applets
    Replies: 4
    Last Post: October 21st, 2011, 08:52 AM
  4. Embed SWING .JAR in Browser
    By ventrol in forum Java Applets
    Replies: 2
    Last Post: June 9th, 2011, 08:40 PM
  5. Replies: 2
    Last Post: November 5th, 2009, 09:15 PM