I copied some code I picked up from a website about application and session scope. Can someone explain how setAttribute and getAttribute works? what do the actual parameters do? also when i use jsp useBean, i usually have a name, which is the name of my instance. Where in servlet code does it use that name?

mike

ps pls look at code below



<jsp:useBean class="foo.Counter" scope="application" />

The servlet equivalent of the above useBean action is:

foo.Counter counter = (foo.Counter)getServletContext().getAttribute("counter");
if (counter == null) {
counter = new foo.Counter();
getServletContext().setAttribute("counter", counter);
}



----------------------------------------------------------------------


<jsp:useBean id="counter" class="foo.Counter" scope="session" />

The servlet equivalent of the above useBean action is:

HttpSession session = request.getSession(true);
foo.Counter counter = (foo.Counter)session.getValue("counter");
if (counter == null) {
 counter = new foo.Counter();
 session.putValue("counter", counter);
}

_________________________________________________________________
MSN 8 helps eliminate e-mail viruses. Get 2 months FREE*. http://join.msn.com/?page=features/virus



--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to