• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Using jsp:useBean across JSPs

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

I have a problem with 3 JSPs, say A.jsp and B.jsp and A.jsp includes B.jsp

A uses a useBean named 'userinfo' which is picked from the session initialized in C.jsp.
If I directly access A.jsp everything works fine.

Heres the problem:
I have to access both A(B included) and B separately.
If I try to access B.jsp which expects a 'userinfo' object I get JSP compilation errors,
and if provide the same userBean from C.jsp

in B.jsp, B.jsp works fine, but then A.jsp fails to load and says duplicate object: userinfo(one from B and the other from C).

And B does not and cannot include C.jsp, which would have solved the problem.

Is there any solution for this issue?

Thanks
Sharma

 
Sheriff
Posts: 67745
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Avoid using useBean and set up the beans in the page controllers.

If you don't use page controllers, you should. Please see this article.
 
Ranch Hand
Posts: 47
Oracle Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Kumara,

Why do you want to have an object of org.ex.UserInfo in both JSP's. If your requirement suffice then I would prefer to have this object created in B.jsp and as you are including it in A.jsp then you would automatically get access to this object from B.jsp. I am not sure about include standard action but include idrective should do the job!

Makes sense?

Regards,
Himanshu
 
Bear Bibeault
Sheriff
Posts: 67745
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
An include will not cause the same object instance to be shared across JSP pages.
 
himanshu.harish agrawal
Ranch Hand
Posts: 47
Oracle Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:An include will not cause the same object instance to be shared across JSP pages.



Hello Bear,

I could get the access to object created in included JSP into including JSP, both though include directive and standard action.
I think we can get the access.

Please let me know if I am going in wrong direction.

Regards,
Himanshu
 
Bear Bibeault
Sheriff
Posts: 67745
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You will have to be clearer about what you are doing.
 
himanshu.harish agrawal
Ranch Hand
Posts: 47
Oracle Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:You will have to be clearer about what you are doing.



Precisely, I am creating an object in A.jsp; including it another JSP through include directive and include standard action. And I am able to access the properties of that object in both the cases.
You can try the same and I hope you will get the same results.

In nutshell: We can access the object created in one JSP into another JSP through include directive and include standard action.


Regards,
Himanshu
 
Bear Bibeault
Sheriff
Posts: 67745
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Of course you can access the property of the created bean in both case, but in no way is that the same instance of the object.
 
Ranch Hand
Posts: 290
Debian Fedora Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:Avoid using useBean and set up the beans in the page controllers.

If you don't use page controllers, you should. Please see this article.


Bear i loved the article thank you for posting.
 
Not looking good. I think this might be the end. Wait! Is that a tiny ad?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic