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

Accessing list from multiple jsp pages (Simple question)

 
Michael Jammy
Greenhorn
Posts: 11
Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Sean Clark
Rancher
Posts: 377
Android Java Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Michael Jammy
Greenhorn
Posts: 11
Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 377
Android Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic