File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes passing bean/class to linked page Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "passing bean/class to linked page" Watch "passing bean/class to linked page" New topic
Author

passing bean/class to linked page

Joel Sander
Ranch Hand

Joined: Jan 09, 2009
Posts: 38
Hi,

I'm pretty new to JSP but have a fair knowledge of java. I am using Tomcat 6. I have a class file that I have setup as a bean:



When the user clicks on a link, I would like access to the class to be passed to the linked page. Can anyone advise me on how this is done?

Thanks!!

Joel
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61761
    
  67

As this is not Tomcat specific, I've moved it to the JSP forum.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61761
    
  67

Because you have placed the instance in session scope, it will still be there when the next page is displayed.
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
Bear Bibeault wrote:Because you have placed the instance in session scope, it will still be there when the next page is displayed.
Assuming that the page is located in the same webapplication context.

If it is located in a different context, but in the same appserver, you need to configure the appserver to share the session among contexts. Consult the appserver specific documentation if it is possible and if so how. If it isn't possible, then consider using a shared database or -only if the data is small and the client supports it- a cookie.

If it is located in a different domain, then you need to pass it as request parameter. Or if it is accessible from both servers, a shared database may also help.
Joel Sander
Ranch Hand

Joined: Jan 09, 2009
Posts: 38
Thanks for moving this to the proper forum.

I have an array of my class MyClass[] myClass that is loaded from a database. When the link is clicked, I want the appropriate element in the array to be set: class = myClass[i];, so that the appropriate class is available to the linked page.

The linked page will be in the same domain.

Joel
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
Joel Sander wrote:

The linked page will be in the same domain.


Is it also in the same context? If it is, then it is just accessible exactly the same way as it is in the 1st page.
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
Joel Sander wrote:Hi,

I'm pretty new to JSP but have a fair knowledge of java. I am using Tomcat 6. I have a class file that I have setup as a bean:


By the way, that exclamation mark doesn't belong there. Remove it.
Joel Sander
Ranch Hand

Joined: Jan 09, 2009
Posts: 38
Bauke Scholtz wrote:
Joel Sander wrote:

The linked page will be in the same domain.


Is it also in the same context? If it is, then it is just accessible exactly the same way as it is in the 1st page.


Please bear with me here. What does it mean to be in the same context?
Joel Sander
Ranch Hand

Joined: Jan 09, 2009
Posts: 38
Bauke Scholtz wrote:
Joel Sander wrote:Hi,

I'm pretty new to JSP but have a fair knowledge of java. I am using Tomcat 6. I have a class file that I have setup as a bean:


By the way, that exclamation mark doesn't belong there. Remove it.


Sorry, that was a bad copy/paste. The jsp page I copied from was included from another page that didn't have the exclamation mark.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61761
    
  67

Bauke, if someone doesn't mention moving to a new context or domain, it's best not to complicate the discussion and assume the same web app.

Joel, in the servlet/JSP world, a context means a deployed web application.
Joel Sander
Ranch Hand

Joined: Jan 09, 2009
Posts: 38
Bear Bibeault wrote:Bauke, if someone doesn't mention moving to a new context or domain, it's best not to complicate the discussion and assume the same web app.

Joel, in the servlet/JSP world, a context means a deployed web application.


Thanks, Bear, for the clarification. This is in the same context. I think that I am able to pass the class now...the current bugaboo is that the class is null. This is simply because as a newbie, I don't know how to invoke the class = myClass[i]; properly in the link.

some link doesn't work. I'm sure there is a better way to do this, but I don't know it.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: passing bean/class to linked page