1

Continued from this question: Set array values in javascript from JSTL code.

I tried using the solution the other member of the forum suggested to me,but it still does not seem to be working.As in,the line:

sessionId.push("${id}");

on the Eclipse IDE becomes:

 sessionId.push("");

on the browser(when I do a view-source).

That member also told me there could be a null element or empty string in the array,does the array:

"["Environment", "1", "Education", "1", "Disaster_Accident", "1", "Hospitality_Recreation", "2", "Labor", "1", "Human Interest", "3"]"

considered to have a null element or string?

1
  • Why does your "array" have double-quotes around it? Typo in your question, or something weird in your real code? Commented Nov 5, 2012 at 4:11

1 Answer 1

0

You probably have a syntax error somewhere. Please try using this demonstration page. It works for me in IE8 browser.

<%@ page import="java.util.*,java.io.*" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> 
<%
   //scriptlet is for testing,
   List<String> list = new ArrayList<String>();
   list.add("Environment");
   list.add("1");
   list.add("Education");
   list.add("1");
   list.add("Disaster_Accident");
   request.setAttribute("arrayList", list);
%>
<script>
var sessionId = [];
<c:forEach items="${arrayList}" var="id">
       sessionId.push("${id}");
</c:forEach>
alert(sessionId);
</script>
Sign up to request clarification or add additional context in comments.

1 Comment

I guess I forgot to import a JSTL jar file,thank you for your solution.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.