Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes JSP and the fly likes unable to access requested scoped attribute in page scoped JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "unable to access requested scoped attribute in page scoped JSP" Watch "unable to access requested scoped attribute in page scoped JSP" New topic
Author

unable to access requested scoped attribute in page scoped JSP

Anil Deshpande
Ranch Hand

Joined: Jan 13, 2008
Posts: 119
I am trying to pass the Person object as an attribute request instance of a servlet. Then I am trying to catch that in JSP page using standard actions. When I use scope="request" I can access the values that I have sent from the servlet (i.e Anil, 18), But when I remove the scope (by default page scope) I cant access the object that i have sent from the servlet. It displays Ajay ,20.

Is there any possibility os sending attributes page scoped from the servlet. How to solve this problem. If I want to access the Anil,18 whethe I have to make scope="request" in standard actions.





The sevlet code:


The JSP code is



This is where the problem is. It is displaying Ajay, 20 (Initialized in JSP) Though I have passed the person attribute in request scope


Please help.


Anil Deshpande
SCJP 1.5, SCWCD 1.5
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Anil Deshpande wrote:
Is there any possibility os sending attributes page scoped from the servlet.


As far as i know, page scope should use in jsp side only.also you cant share it across the request . why you dont prefer request scope?

Anil Deshpande
Ranch Hand

Joined: Jan 13, 2008
Posts: 119
No problem with request scope. But I came to know that in jsp it basically makes use of findAttribute() method. So naturally the person attribute would be searched from request, session,context scope and so on. So according to that It sould be able to fing person attribute from request. Not directly initialize person because it doesn't locate it in page scope
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Anil Deshpande wrote: But I came to know that in jsp it basically makes use of findAttribute() method.


Not jsp. pageContext (implicit object) has the findAttribute method
karan wadhwani
Greenhorn

Joined: Feb 22, 2005
Posts: 12
But this is correct way...as you are setting object in request, it is better to use request to take it out.
In JSP you can set the any object in page scope using c:set [jstl].
Anil Deshpande
Ranch Hand

Joined: Jan 13, 2008
Posts: 119
I think I foud something that makes sense. By default it is always "page" scope in standard actions. If we want to access something from any other scope then we have to mention it explicitly like "request", "session" and so on. Am i right?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: unable to access requested scoped attribute in page scoped JSP
 
Similar Threads
jsp:usebean not working
<jsp:getProperty> returns nothing
jsp:useBean
<jsp:setProperty>
Param Attribute doubts