Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

passing bean/class to linked page

 
Joel Sander
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64829
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As this is not Tomcat specific, I've moved it to the JSP forum.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64829
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because you have placed the instance in session scope, it will still be there when the next page is displayed.
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64829
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic