Same variable on every JSP page

S

Steven

Hi All,

I'm just a beginner with JSP so excuse me if this is a 'stupid' question.

I'm building an Application that uses MySQL database everything works ok,
but
I would like to know if there is a way to have a variable that I can use on
every page.

The reason is, is because I have lots of pages (and growing) where I have
the
database connect string with username password, but due to security reason
the user/pass for the database will change every now and then.

I'm familiar with Coldfusion and in Coldfusion you can setup an
Application.cfm file. This file is called before every other .cfm file. Is
there something like that
in JSP?

The solution I thought of is, putting the connect string into a session
variable.
Is this a could idea?

If not, are there any other better ways of achiving this?

Thanks for any help!

Steven.
 
V

Viator

I suspect that you want to use a perticuler Object rather than a
variable on your every page. If so just create the Object and set it as
an attribute of the session object.
______________________________________________________________________
SomeObject so=new SomeObject();
session.setAttribute("Key",so);
Of course you will use following code in your other pages to access the
Object:
SomeObject xso=(SomeObject)session.getAttribute("Key");
Let the SomeObject class keep track of database details with a method
like
SomeObject.getuserName();

Viator :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,900
Latest member
Nell636132

Latest Threads

Top