• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Global String object?

 
Ed Carrington
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In Tomcat 4.1.27 how can I create a String object that I can call in any of my Java classes?

For example I have a String object like this: String mymessage = "hello world";

Anyway I can put that in web.xml or some other file and call the mymessage variable in any Java class?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64959
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Without telling us what you intend for the string, what's wrong with good old:



?

This is, of course, not Tomcat or even web app specific.
 
Ed Carrington
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Bear Bibeault:
Without telling us what you intend for the string, what's wrong with good old:



?

This is, of course, not Tomcat or even web app specific.


Thanks for your quick response.
Where do I put that so I can call it anywhere in my webapp (called ProjectOne) folder: System.out.println(GLOBAL_STRING);
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64959
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is just basic Java. You can put it in any class and reference it (since it is static) using the class name.

Note that many people would frown up globals such as this. You still haven't told us what you want to do with this string. Someone might have suggestions for better practices.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic