Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

<c:set Usage

 
Sai Surya
Ranch Hand
Posts: 463
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear All,

I am trying to create one request scoped attribute (map) using <c:set var and trying to add values to this map using ><c:set target.
Here is my code:

jspform.jsp


jspformsubmit.jsp


When I run this code, I am getting exception. I suspect that something is wrong with the way I am using <c:set in the jspform.jsp.
How do we set a HashMap or Object using ><c:set var to any scope?

>
 
Ankit Garg
Sheriff
Posts: 9577
33
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are creating the myMap in request scope and then adding values to it in a different page. When the browser will make request for that page, that will be a new request. So the myMap won't be there in that scope. Try using session scope...
 
Sai Surya
Ranch Hand
Posts: 463
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I changed the scope to session. But I got JspException as before.



Since <c:set var is used to set scoped attributes, I need to have 'myMap' of type Map to put it in scope.
Where do I need to create this map?>
 
Chinmaya Chowdary
Ranch Hand
Posts: 434
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Sai.
In jspform.jsp, there is
<c:set var="myMap" scope="session" value="${myMap}"/>


Here 'value' attribute, gets the 'myMap' attribute i.e present in 'session' scope. I think you are not set this attribute in session scope.
 
Sai Surya
Ranch Hand
Posts: 463
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, I set myMap in the session from another servlet and it worked. I understood the concept. Thank you
 
Chinmaya Chowdary
Ranch Hand
Posts: 434
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Sai.
Here 'value' attribute, gets the 'myMap' attribute i.e present in 'session' scope.

I am sorry, I made a mistake here. Since, value="${myMap}", EL will looks not merely in 'session' scope. It looks in all scopes starting from (page, request,session, application) and gets the attribute and sets it into 'session' scope, since c:set attribute's scope is 'session'.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic