Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Set tag for adding array list object to request scope  RSS feed

 
parvez Moinuddin
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All
can any body please tell me how to add an ArrayList object to request scope using set tag
My code is as below



<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ page isELIgnored="false" %>
<%@ page import="java.util.*" %>
<%
ArrayList a=new ArrayList();
a.add("one");
a.add("two");
a.add("three");
a.add("four");

%>
<c:set var="aaa" value="${a}" />
<c:forEach var="i" items="${aaa}" >
<c:out value="${i}" />
</c:forEach>


After executing above jsp I am getting blank value in browser

Thanks in advance
 
Paul Clapham
Sheriff
Posts: 22374
42
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you want to do it within a Java scriptlet (not a good idea) then you would do exactly as you would do it within a servlet (which is a better idea anyway).
 
Stefan Evans
Bartender
Posts: 1836
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From java code, you add an item to request scope by calling request.setAttribute method.

In your case request.setAttribute.("aaa", a);


${aaa} evaluates as pageContext.findAttribute("aaa") and would thus then find your request attribute.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66141
141
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Using scriptlets in a JSP ia bad idea.

Mixing scriptlets with JSTL and EL code is even worse, and nothing short of madness.

Stop the madness.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!