Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Using jsp:useBean across JSPs

 
Kumara SharmaS
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • 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

 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65227
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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.
 
himanshu.harish agrawal
Ranch Hand
Posts: 47
Java Linux Oracle
  • Mark post as helpful
  • send pies
  • 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
Author and ninkuma
Marshal
Pie
Posts: 65227
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
Java Linux Oracle
  • Mark post as helpful
  • send pies
  • 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
Author and ninkuma
Marshal
Pie
Posts: 65227
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You will have to be clearer about what you are doing.
 
himanshu.harish agrawal
Ranch Hand
Posts: 47
Java Linux Oracle
  • Mark post as helpful
  • send pies
  • 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
Author and ninkuma
Marshal
Pie
Posts: 65227
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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.
 
Arun Giridharan
Ranch Hand
Posts: 290
Debian Fedora Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic