Forums Register Login

Can an attribute set in request scope be found by JSP standard actions in session scope?

+Pie Number of slices to send: Send
Hi
I have a jsp which is displaying a bean property called name and the bean is PersonVO

=========
PersonVO
=========


I am displaying this with the following code


by hitting the servlet PersonServlet



but what i dont understand is i set the personvo object in request scope in servlet and iam trying to find the personvo object in session scope using jsp standard action but it was able to find it

the code in person_jsp.java is


Even in above code it is trying to get the attribute personvo from session scope but i set the personvo object in request scope in my servlet

Can some on explain me why?
+Pie Number of slices to send: Send
You cannot set something in request scope, and expect it to be available in another scope.

If you put your socks in the top drawer, would you be surprised to find that they are not also in the bottom drawer? Of course not! Why would you expect your socks to be available in session scope if you put them in request scope?
+Pie Number of slices to send: Send
Bear

As you can see i put personvo attribute in request scope in PersonServlet



and accessin in JSP using jsp standard action tag with session scope..



how is it possible even in the translated jsp to servlet it is finding the attribute in session scope and it was able to get it how is it possible



My question is how an attribute set in the request scope was found when searched using the session scope??
+Pie Number of slices to send: Send
Are you sure you want to invoke the jsp:useBean? I think you don't need that as you are already setting the request attribute in the servlet, you can just access it in your jsp directly:

+Pie Number of slices to send: Send
Yes i can do that..

My question is i set the attribute in request scope and im trying to find that attribute in session scope in jsp using jsp:usebean.

and it could able to find it i would like to know how it was able find an request scoped attribute in the session scope..
+Pie Number of slices to send: Send
By using the useBean you are creating a new instance of PersonVO and setting it in the Session scope, that might be the reason why your generated Servlet is trying to access it. I am not an expert in JSPs but I think if you change the scope to request you might get to use the one you set in your Servlet.
+Pie Number of slices to send: Send
Here it is plain as day: you can't. If you place the scoped variable into request scope, you need to look for it in request scope. It's not in session scope, so you can look there as hard as you like, but it's not there. Never will be.

If you put your dinner down on the kitchen table, would you expect it to magically appear in the bedroom? No, you put it in the kitchen, so you need to go back to the kitchen to get it.

If you put the variable into request scope, you need to get it from request scope. Simple.
+Pie Number of slices to send: Send
Think of the different scope as different hashmaps.
Story like this gets better after being told a few times. Or maybe it's just a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1703 times.
Similar Threads
getproperty in jsp
how do i use html:select to forward to different pages?
Error in simple bean and JSP
how to obtain list object from an actionform
jsp:setProperty question
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 11:25:13.