wood burning stoves 2.0*
The moose likes JSP and the fly likes How can i get session value in my JSP page using JSTL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "How can i get session value in my JSP page using JSTL" Watch "How can i get session value in my JSP page using JSTL" New topic
Author

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

saravanan sambandam
Ranch Hand

Joined: Aug 30, 2010
Posts: 42
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

Joined: Jan 27, 2011
Posts: 21

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

Joined: Jan 10, 2002
Posts: 60050
    
  65

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

(But really, "SMGR"? I'd pick a more readable variable name.)


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
saravanan sambandam
Ranch Hand

Joined: Aug 30, 2010
Posts: 42
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

Joined: Jan 27, 2011
Posts: 21

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

Joined: Aug 30, 2010
Posts: 42
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

Joined: Jan 27, 2011
Posts: 21

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

Joined: Aug 30, 2010
Posts: 42
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

Joined: Jan 10, 2002
Posts: 60050
    
  65

Joe Martin,
Your post was moved to a new topic.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How can i get session value in my JSP page using JSTL
 
Similar Threads
Edit or delete records resulting from search
Problems with converter in h:selectManyCheckbox
Problem with iterator for checkboxes. How to set value to bean property?
JSF h:selectOneMenu concern
How can i get session value by using JSTL