• 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
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

<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'.
 
You would be much easier to understand if you took that bucket off of your head. And that goes for the tiny ad too!
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic