> 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
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.