Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Is it possible to pass an object into a JSP using <jsp:include>?  RSS feed

 
Kim Forbes
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have three JSPs - HardwareAsset, SoftwareAsset, ServiceAgreement. Each JSP needs a section displaying the name and contact details of the author. So I have created another JSP - authorDetails - and I use this in each of the three main JSPs by using <jsp:include>.

The name and contact details of the author is stored in a bean called User. How can I pass this User bean object into the authorDetails form?

I have tried passing it as a param like this:



but it seems you can only pass Strings in as params and not other objects.

The only option I can think of is to set the authorBean as an attribute on the request in the servlet rather than trying to pass it in the JSP. Is this how I should do it?

Thanks.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Put the author in the request scope.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65830
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you thought of using a JSP tag file rather than an include?
 
Kim Forbes
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for your suggestions, I came up with another way of doing it:

I created a bean class called Asset with the author object. I then made the HardwareAsset, SoftwareAsset, ServiceAsset classes all extend the Asset bean class.

Then I referenced the parent Asset bean in the authorDetails JSP like this:



and the authorDetails subform could find the author object in all three forms as they all had beans that extended the parent Asset bean.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the author is in the request scope they'd be able to access it from the request scope regardless of parent class.
 
Kim Forbes
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Having the parent class worked best for me because I actually had more shared objects that I needed to reference such as createdDate and an editHistory. It seemed easier than adding all these different objects to the request each time.

Thanks for your help.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!