This week's book giveaway is in the HTML Pages with CSS and JavaScript forum.
We're giving away four copies of Testing JavaScript Applications and have Lucas da Costa on-line!
See this thread for details.
Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

<c:set Usage

 
Ranch Hand
Posts: 463
Eclipse IDE Tomcat Server Java
  • 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?

>
 
Sheriff
Posts: 9671
42
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • 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 Tomcat Server Java
  • 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?>
 
Ranch Hand
Posts: 437
Oracle Java
  • 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 Tomcat Server Java
  • 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: 437
Oracle Java
  • 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'.
 
    Bookmark Topic Watch Topic
  • New Topic