• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

unable to access requested scoped attribute in page scoped JSP

 
Anil Deshpande
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic