common variables in diff. JSP

dear all i have diff. JSP, they are also want to share a common variable, is it a efficient way to code that? i don't want to use a method that using GET method transferring from one page to another page. thanks yan
[253 byte] By [chungyan5] at [2007-9-26 4:08:30]
# 1
You can store your variable on Application or session to share their value in multiple pages.is this u want ?
atifkhaliq at 2007-6-29 13:10:45 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
thanks your reply, atifkhaliq yes it is what i need, but can you describe more deeply and more technique, since i am the new in web programming, i just has experience in javaprogramming thanks a lot
chungyan5 at 2007-6-29 13:10:45 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3
Hi chungyan, Please look at this url http://java.oreilly.com/news/jsptips_1100.htmlTirumalaraoDeveloper Technical Support, Sun Microsystems, http://www.sun.com/developers/support
rao_indts at 2007-6-29 13:10:45 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4

> dear all

> i have diff. JSP, they are also want to share a

> common variable, is it a efficient way to code that?

> i don't want to use a method that using GET method

> transferring from one page to another page.

> thanks

> yan

Dear Yan

We can use session varaibles

like declare a session variable after you got thru the first page in JSP code as below:

session.putValue("SessVar", SessVarInf);

where we are creating a session object with name as "SessVar" and we are assign the value to "SessvarInf", where the "SessvarInf" can be a string or a variable. but remember this is a string object.

To get back the session variable please ensure to declare a variable in the Corresponding JSP Page where u can get back the value it is like as follows:

String GetSessionValue = (String)session.getValue("SessVar"); and u can access the GetSessionValue in the corresponding pages, remember that GetSessionValue return "null" if the session is expired.

Hope this may help u better.

Rambee

rambee at 2007-6-29 13:10:45 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5

Hi,

if your variable is common to several JSP for all clients use :

<jsp:useBean id="instanceName" class="full.class.name" scope="application"/>

if it is common to several JSP but different for each client change scope to "session"

(this line must be add to all your JSPs which need that variable)

If your variable is the same for all client and you know its value without needing a first client connection create a JSP which will init the variable(s) in its public void jspInit() method and run the JSP on server startup changing your web.xml file.

Hope this helps.

gentyt at 2007-6-29 13:10:45 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...