• Post Reply Bookmark Topic Watch Topic
  • New Topic

Portable Parameters

 
Steve Dyke
Ranch Hand
Posts: 1716
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know this might not be the correct area for this question but it is the closest one I could find.

Is session attributes the only portable(global) parameters in a web app?

Is there something else I could do to assign a value to a parameter in the start up of a session and use it in any servlet, class, jsp, etc in the app?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65519
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Portable? I don't see how that word applies here.

If you are asking about a value that's available throughout the web application, and not specific to a particular session, then that's what application scope is for (see ServletContext.setAttribute()).

A context listener is a great place to set up such values.
 
Steve Dyke
Ranch Hand
Posts: 1716
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:

If you are asking about a value that's available throughout the web application, and not specific to a particular session, then that's what application scope is for (see ServletContext.setAttribute()).

A context listener is a great place to set up such values.


I am talking about a value that is set in the session, based on log on status and roles. Then use that value through out that independent session.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65519
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, that's exactly what session scope is. You set a value into the session and it stays there, limited to that particular session, until you either remove it or the session terminates.
 
Steve Dyke
Ranch Hand
Posts: 1716
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:Well, that's exactly what session scope is. You set a value into the session and it stays there, limited to that particular session, until you either remove it or the session terminates.


But how do you make it avaliable to any servlet, jsp, class?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65519
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The session is already available to all servlets and JSPs. The session (and other servlet resources) should not be used in any other class. If a non-servlet needs data from the session, the controller layer should grab it and pass that data as parameters.
 
Steve Dyke
Ranch Hand
Posts: 1716
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:The session is already available to all servlets and JSPs. The session (and other servlet resources) should not be used in any other class. If a non-servlet needs data from the session, the controller layer should grab it and pass that data as parameters.


Thanks.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!