Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6090085
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:10:24+00:00 2026-05-23T12:10:24+00:00

I know how to use $.each in my program which is written in Java

  • 0

I know how to use $.each in my program which is written in Java
like this

$.each( ['a','b','c'], function(i, l){ 
   alert( "Index #" + i + ": " + l ); 
 });

what about If I want to pass arraylist or string array from my java program to the JQuery any one knows how??

I wrote

String[] arr1=new String[2];
arr1[1]="whatever";
arr1[2]="ksj";
$.each( arr1, function(i, l){ 
   alert( "Index #" + i + ": " + l );
 }

but it does not work?


Update:: I have jsp page which contains part of java as follows:

<%@page import="java.lang.reflect.Array"%>
<%@page import="java.util.ArrayList"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>

        <style>
            .highlight { background-color: yellow }
        </style>
    </head>
    <body>
        <h1>Hello World!</h1>
        <%  ArrayList wordslist = new ArrayList();
      wordslist.add("Hello");
      wordslist.add("again");

     String[] arr1=new String[wordslist.size()];
      for (int i=0; i<wordslist.size();i++)
      {
     arr1[i]=wordslist.get(i).toString();
        }%>



        <a href="http://jquery.com/">jQuery</a>

        <p> Hello again and again</p>
          <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
       <script src="jquery.highlight-3.js"></script>
       <script>

        $(document).ready(function(){
       alert( arr1 );     
      var arr=new Array();
      arr.

$.each( arr, function(i, l){ 
   alert( "Index #" + i + ": " + l );
 }
)


     });

       </script> 
    </body>
</html>

The problem is wordslist arry is dynamic and I want to pass it to the JQuery ?? How can I do that without using inline embedded java please help Is there a way to pass wordslist to arr array in the Jquery!!!
This really make me disappointed!!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T12:10:25+00:00Added an answer on May 23, 2026 at 12:10 pm

    Use a JSON library for Java. Then serialize your ArrayList to JSON:

    ArrayList wordslist = new ArrayList();
    wordslist.add("Hello");
    wordslist.add("again");
    
    String json = (new JSONArray(wordslist)).toString();
    

    Echo the JSON text at the appropriate place in your JavaScript code. E.g.

    $(document).ready(function(){    
        var arr = <%= json %>;
        $.each( arr, function(i, l){ 
            alert( "Index #" + i + ": " + l );
        });
    });
    

    I’m actually not sure whether this is the right JSP syntax for printing a variable. Please correct if not.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Java program which its main method (in the main class) expects
I know what a static array is and how to use it in Java,
I am implementing a haskell program which compares each line of a file with
I know the use of server-side controls is a no-no in ASP.NET MVC, however
I know how to use tags in subversion. I create a tag every time
I know how to use JSON to create objects, but there doesn't seem to
I know you can use C++ keyword 'explicit' for constructors of classes to prevent
I know you cannot use a alias column in the where clause for T-SQL;
I know how to use the OleDbConnection class to open an excel file and
I know you can use the <jsp:useBean> tag to instantiate objects within JSPs without

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.