Passing a parameter from controller to jsp using Map

A parameter can be passed from controller to jsp in several number of ways.Using MAp is one of those ways . Following is the code snippet of how parameter can be passed through map :

Controller.java

Map<String, Object> passParameter() {
final Map<String, Object> responseMap = new HashMap<String, Object>();
responseMap.put("quant", 11);
return responseMap;
}

Hello.jsp 


<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<div class="quantValue">
<c:if test="${quant}">
<c:out>Value of quant is ${quant} </c:out>
 </c:if>
</div>


In the above scenario, a parameter "qauant" is set in map. This map value is then read on jsp using ${quant}. 
Plain and easy. :)

					
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s