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 116263
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T03:09:01+00:00 2026-05-11T03:09:01+00:00

I have a list of strings on my server which I am trying to

  • 0

I have a list of strings on my server which I am trying to get to the client in the form of an array. The code I am attempting to use is the following:

Within the jsp I have a List<String> column

I am attempting the following code:

<%int j = 0; %> for(var i = 0; i < <%=columns.size()%>; i++) {   colArray[i] = '<%=columns.get(j++)%>'; } 

This code simply returns the first element in the columns list for every element in the colArray.

I have also tried:

colArray = <%=columns.toArray()%>; 

which does not work either. I feel like I am making a little mistake somewhere and am just not seeing it. Is what I am trying to do possible in the way that I am attempting?

Thanks.

  • 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. 2026-05-11T03:09:02+00:00Added an answer on May 11, 2026 at 3:09 am

    You’re getting the JSP code that is executed on the server mixed up with the JavaScript code that’s executed on the client. The snippet <%=columns.get(j++)%> is executed once, on the server, and the JavaScript loop around it is irrelevant at this point. When it arrives the the client, the loop’s body just says colArray[i] = 'first entry'; which of course puts the same string into every element of the array.

    What you need to do instead is to have a loop execute on the server, like this:

    <% for (int i=0; i<columns.size(); i++) { %> colArray[<%= i %>] = '<%= columns.get(i) %>';  <% } %> 

    My JSP skills are rusty, and the syntax may be different, but I hope you get the idea.

    Edit: As was pointed out in the comments, you need to be VERY careful about escaping anything in those Strings that could cause them to be interpreted as JavaScript code (most prominently quotation marks) – especially if they contain user-generated content. Otherwise you’re leaving your app wide open to Cross-site scripting and Cross-site request forgery attacks.

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

Sidebar

Related Questions

i'm trying to get the list of mime types known to an IIS server
Trying to get a list of drives from a server side application using a
I am trying to code a small website which just uses a form. I
I have list of strings like this FirstName-Lastname (separated by a dash -) I
I have a List of Strings. EXAMPLE_1, EXAMPLE_2, EXAMPLE_3 ... EXAMPLE_99 What is the
I have a list of strings similar to this list: tags = ('apples', 'apricots',
I have sorted list of strings that I move between php and java. to
I have a list of strings that I need to pass to a process
I have a list of strings in kumo . I am printing three strings.
I have a list of strings like this: my_list = ['Lorem ipsum dolor sit

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.