I want to collect values from a JSP page and pass it dynamically to another JSP page with the help of JSTL. How can I do this?
Asked
Active
Viewed 5,729 times
1 Answers
4
You use a request scoped HashMap for that.
Example
1) Declare the HashMap in each JSP you want to insert or access the list of values.
<jsp:useBean id="map" class="java.util.HashMap" scope="request"/>
Note: The scope="request" is what makes it accessible in other JSPs.
2) Stuff information into the HashMap
<c:set target="${requestScope.map}" property="city" value="${param.city}"/>
<c:set target="${requestScope.map}" property="state" value="${param.state}"/>
<c:set target="${requestScope.map}" property="phone" value="${param.phone}"/>
3a) You can now pull out the values in a different JSP by simply doing:
<c:out value="${requestScope.map['city']}"/>
-or-
3b) You can also iterate over that HashMap in a different JSP:
<c:forEach items="${requestScope.map}" var="item">
${item.key} = ${item.value}<br/>
</c:forEach>

alfreema
- 1,308
- 14
- 26