Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How can i get session value in my JSP page using JSTL

 
saravanan sambandam
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Friends,

i am new to java and i have assigned a task that i need to get value from Session value using JSTL. I know how to get session values using java script let. But i don't know how to get session value using JSTL.

I gone through some examples and followed as it is. But its not getting value using JSTL.

What i done.

In our application we have created sessionManager class, in that class we have used setter/getter methods. Through this method we will get / set the values into sessionManager object. This sessionManager object has been added into session object.

Using session.setAttribute("SMGR", sessionObject);

i am getting output

navigation.jsp ** myPage jsp size - 3
page Name ********: menuManager
page Name ********: userManager
page Name ********: userTypeManager



i am getting values in my JSP page using scriptlet .

while using JSTL i didn't get the value. Where i done the mistake. This is my JSTL code.
 
Markas Korotkovas
Greenhorn
Posts: 21
Eclipse IDE Java Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It looks like you are setting the object into session using "SMGR" as the attribute name. When using JSTL to get it from session you need to be using that same name:
sessionScope.SMGR....
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64827
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You use the EL, not the JSTL: ${SMGR}

(But really, "SMGR"? I'd pick a more readable variable name.)
 
saravanan sambandam
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi.

Thanks for your response, but i did not get you.

Please tell me. What i need to do there?

You use the EL, not the JSTL: ${SMGR}

(But really, "SMGR"? I'd pick a more readable variable name.) -- "SMGR" is a attribute name to get the object from session. after that i want to get pageList as an arrayList type Object. So far i used property myAccessPage, which has both getter & setter method.


It looks like you are setting the object into session using "SMGR" as the attribute name. When using JSTL to get it from session you need to be using that same name:
sessionScope.SMGR....

even i tried with your guideline. I didn't get the result. I made the mistake some where and i uable to identify.




Could you point me where i did the mistake.

Thanks
Saravanan.s.
 
Markas Korotkovas
Greenhorn
Posts: 21
Eclipse IDE Java Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Interesting that in your scriplet you are using the "sessionManagerVariable" to get the sessionManager object from session. But in the JSTL tags you are not using the same name. Are there several different session manager objects in the session or am i missing something?
 
saravanan sambandam
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi! thanks you pointing out me mistakes.

I tried after i changed my code. Till i am getting the no result. Please give me some sample code. It would help me more..

 
Markas Korotkovas
Greenhorn
Posts: 21
Eclipse IDE Java Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As with any other technology you should start with the most basic thing in order to make more complex things later. In your code example you are trying to create a menu using an iterator with an if statement inside as well without having figured out the basics. Start small. Try to get a string attribute from the manager (if available) and output it to the page. Once you can get that working get the simple iterator with static text inside working. Once that is done start adding other elements and etc. I know it is tedious, but that is the way to learn. If i provided you with a solution right away you would not learn and i would be doing all the work for you.
 
saravanan sambandam
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys,

Thanks for your supports.

I got the result by this ${sessionScope.SessionVariable.accessPage}

sessionScope <--> session
SessionVariable <--> attribute name
accessPage <--> one of the property
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64827
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Joe Martin,
Your post was moved to a new topic.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic