• 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

A better approach to declaring variables in JSPs

 
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is there a better way to declare vars in jsps I have about 12 jsp pages where the below code is repeated for variables passed in to my taglibs.

If I want to add a variable I have to do it in 12 places.

Reg


 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My advice is to punt back and remove all Java from your JSPs and adopt scriptless pages using an MVC architeture and the JSTL/EL.

But if that's too big a step for you I'd at least put the common code into an include file so that it exists only once in the source tree.

But think of my first suggestion. Seriously.

Really.
 
Reggie McDougal
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Bear,

Thanks for the reply.

If I use a taglib let say the one below I'm passing these parameters
by appending to a url, I still have to declare the vars in my jsp page for it to work and use request object to get the parameters.

Is there another way to declare and get the params, or do I still have to
have some scripting in my jsp?

Reg



 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hard to say without more context.

Are you running JSP 1.2 or JSP 2.0? It's much easier with the latter to simplify your JSP pages.
 
Reggie McDougal
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Using Weblogic 8.1 which support the 1.2 spec

Reg
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Then you are kind of stuck using scriptlet expressions for the dynamic attributes of custom tags. Under JSP 2.0, you can use the EL for these.

In prep for that, I would look into factoring out as much of the Java as possible from the pages, but you won't be able to do so 100%.

How are all these variables getting set? Why do you need to carry them page to page? If they are a common set that are used on multiple pages, why are they not session variables?
 
Reggie McDougal
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So I should set these in the session object? and get them as I need them?

Reg
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Reggie McDougal:
So I should set these in the session object? and get them as I need them?

Reg



Does using value bean and passing them via either session or request make it easier for you?
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If they are indeed values that need a scope higher than the page/request level, then the session is the appropriate place for them if they are per user. If they are application global, then the application context can be used.

In either case, be sure to clean up after yourself when you are done with them.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic