Author Topic: How do i specify Application-level variables in JSP?  (Read 199 times)

0 Members and 1 Guest are viewing this topic.

Offline MrSpecialist

  • Sr. Member
  • *
  • Posts: 342
  • Karma: +1/-0
  • I'm an expert!
    • View Profile
How do i specify Application-level variables in JSP?
« on: October 30, 2008, 03:44:40 PM »
I want to do something similar to the global.asa in ASP, where I can specify application and session variables in JSP?

Any ideas?

Techronnati | where technology never sleeps

How do i specify Application-level variables in JSP?
« on: October 30, 2008, 03:44:40 PM »

Mountain View

Offline CyborgRepublic

  • Full Member
  • *
  • Posts: 201
  • Karma: +0/-0
    • View Profile
Re: How do i specify Application-level variables in JSP?
« Reply #1 on: October 30, 2008, 04:18:02 PM »
May you can try this one out. Not familiar with ASP though.

<context-param>

tag in your web.xml. You can then access this value using

application.getInitParameter("param-name");

So in web.xml you would have something like this:

  <context-param>
    <param-name>paramName</param-name>
    <param-value>paramValue</param-value>
  </context-param>

Offline Corps

  • Sr. Member
  • *
  • Posts: 273
  • Karma: +0/-0
    • View Profile
Re: How do i specify Application-level variables in JSP?
« Reply #2 on: October 30, 2008, 04:20:06 PM »
Just sharing what i have in mind....

First, let me say that creating entries in the web.xml <init-param> element is analgous to creating static global variables for your web application. You can then access these variables at runtime using the getInitParameter(_parameterName:String):String method of the ServletContext interface. This method is just used to store String name-value pairs.

For creating and manipulating application-level variables at runtime, you would use the ServletContext methods:
-setAttribute(_attName:String, _attValue:Object):void
-getAttribute(_attName:String):String
-removeAttribute(_attNAme:String):void

The methods above have the advantage of being able to manipulate the variable value at runtime, as well as the ability to store Objects, not just Strings.

The JSP specification defines the implicit object application to access an implementation (provided by the servlet container) of the ServletContext interface throughout your JSP application.

NOTE: Objects placed into the SessionContext can only exist in one VM, so applications marked as distributable over many VM\'s will not be able to see each other\'s application-level variables. This is only an issue in a clustered envrionment.

References:
ServletContext Interface:
Java Servlet Specification version 2.3, Section SRV.3

WebApp Deployment Descriptor:
Java Servlet Specification version 2.3, Section SRV.13

JSP Implicit Objects:
JavaServer Pages Specification version 1.2, Section JSP.2.8.3

 

Related Topics

  Subject / Started by Replies Last post
0 Replies
146 Views
Last post September 28, 2008, 04:23:42 PM
by MrSpecialist
1 Replies
140 Views
Last post November 12, 2009, 05:19:23 AM
by MrSpecialist
1 Replies
75 Views
Last post August 07, 2014, 03:30:06 AM
by Transformer10
0 Replies
27 Views
Last post April 25, 2010, 10:10:20 PM
by rpmolecule
0 Replies
26 Views
Last post September 16, 2014, 01:20:36 AM
by TDelight

Posting Disclaimer: Any individual may post a message in this forum and may do so anonymously. Therefore, the sole author is exclusively and entirely responsible for all opinions in that message. They do not represent the official opinions of Techronnati, its administrators or moderators or the Techronnati Management. Techronnati is merely acting as an impartial conduit for constitutionally protected free speech and is not responsible and will not be held liable for the content of such messages. All images and service logos are trademarks of their respective owners.