aspose file tools*
The moose likes Spring and the fly likes Accessing list from multiple jsp pages (Simple question) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Accessing list from multiple jsp pages (Simple question)" Watch "Accessing list from multiple jsp pages (Simple question)" New topic
Author

Accessing list from multiple jsp pages (Simple question)

Michael Jammy
Greenhorn

Joined: Sep 21, 2011
Posts: 11

Hi there, I have a simple question (for any pro). I want a method to be accessible to all pages (or at least any page I declare), but I only know how to make it accessible on one page. For example, the following method:


This method is in my controller class and can be accessed from localhost:8080/categories/listcategories.htm. So on this page I can use: to show the whole list. But I would also like to access this list from another page, for example from localhost:8080/list.htm

Now I have another method in another Controller class for that page.

I would really appreciate it if someone could help me pass this milestone


Oracle Certified Java Programmer 6
Sean Clark
Rancher

Joined: Jul 15, 2009
Posts: 377

Hey,

You have a number of options open to you, you could:
1) Create a super class which factors out the common code between the 2 methods/classes.
2) Create a CatagoriesService.java class which will provide the common functionality for you and add that in to both classes.
3) If it never changes you could store the attributes in Application Scope so that they are always there. (only really suitable if the data doesn't change!)

Sean


I love this place!
Michael Jammy
Greenhorn

Joined: Sep 21, 2011
Posts: 11

Sean Clark wrote:Hey,

You have a number of options open to you, you could:
1) Create a super class which factors out the common code between the 2 methods/classes.
2) Create a CatagoriesService.java class which will provide the common functionality for you and add that in to both classes.
3) If it never changes you could store the attributes in Application Scope so that they are always there. (only really suitable if the data doesn't change!)

Sean

Hi there,

Isn't there a faster method though? I have a whole lot of classes and probably around 60 methods. Can't I use an annotation or add something to these methods to make them also available somewhere else? Or maybe there is something in the JSP I can do to access the data anyway?
Sean Clark
Rancher

Joined: Jul 15, 2009
Posts: 377

Hey,

Well you can use the @ModelAttribute annotation, however you are still going to need to put that in every controller or create a superclass which has it in it.

Sean
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Accessing list from multiple jsp pages (Simple question)