Does anyone else think it's poor API design that the JSP spec defines
the "application" scope directly in terms of the objects being stored in
the ServletContext ?
It seems very implementation dependant to me, in that it enforces the
implementation of JSP where the page is compiled to a servlet, as well
as forcing the ServletContext will be the container for application
scoped objects. I'm sure I read somewhere in one of the earlier specs
that JSP was designed to *not* be tied to a servlet based implementation
? Is that requirement out the window now ?
I think it would be cleaner to create an abstract definition of an
"application", defined in terms similar to that in ASP (no flames
please). In that environment, all ASP pages under a nominated parent
directory are considered part of the same "application". This defines
an application in terms of the directory the source pages live in,
rather than the runtime context they are executed in. I'm not sure how
this concept would apply to pure servlets though, with their complex
URL-to-servlet mapping schemes ?
I imagine the above would also be more appropraite in the future
load-balancing Servlet and JSP engines which may be spread across
several VM's and physical machines. It's hard to imagine these sharing
a single servlet context to implement a consistent application scope ?
Regards
Drew Cox
Barrack Consulting
> -----Original Message-----
> From: Craig R. McClanahan [SMTP:[EMAIL PROTECTED]]
> Sent: Thursday, 13 May 1999 6:22
> To: [EMAIL PROTECTED]
> Subject: Re: Application scope
>
> Pinky Thakkar wrote:
>
> > Hi,
> >
> > I want to define a variable: index, which has an application scope.
> > {
> > like in ASP, i would write something like :
> >
> > Application("index")=0
> > }
> >
> > How do i do it in JSP?
> >
> > Thanks,
> > Pinky
>
> First thing - you cannot store primitive objects (like an int) in one
> of these
> scopes -- only objects. So, you'd probably create yourself a Counter
> class
> something like this:
>
> public class Counter {
>
> private int value = 0;
>
> public Counter() {
> ; // No-args constructor required for instantiation
> from a JSP
> page
> }
>
> public Counter(int initialValue) {
> value = initialValue;
> }
>
> public int getValue() {
> return (value);
> }
>
> public void setValue(int newValue) {
> value = newValue;
> }
>
> }
>
> Next, you can cause an object like this to be added to the application
> scope
> from either a Servlet or a JSP page. From a servlet, it would be
> created like
> this:
>
> getServletContext().setAttribute("index", new Counter());
>
> and accessed (say, to increment the value) -- ignoring synchronization
> issues
> -- with:
>
> Counter index = (Counter)
> getServletContext().getAttribute("index");
> int currentValue = index.getValue();
> index.setValue(currentValue + 1);
> // Note -- no need to re-store the object
>
>
> From a JSP page (1.0 syntax) create it (if not present already) with:
>
> <jsp:useBean id="index" class="Counter"
> scope="application" />
>
> and access it by using the name specified for the ID ("Index" in this
> example). Essentially, the "Counter index ..." declaration above is
> done for
> you by the JSP page compiler.
>
> Craig McClanahan
>
> ======================================================================
> =====
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the
> body
> of the message "signoff JSP-INTEREST". For general help, send email
> to
> [EMAIL PROTECTED] and include in the body of the message "help".
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JSP-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".