• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Accessing list from multiple jsp pages (Simple question)

 
Greenhorn
Posts: 11
Spring Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Rancher
Posts: 377
Android Spring Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
The two armies met. But instead of battle, they decided to eat some pie and contemplate this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic