You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Michael Wentzel <Mi...@aswethink.com> on 2001/07/06 20:42:59 UTC

RE: Help on application scope

> Dear all,
>     I used a java.util.HashMap for session invalidation in my 
> JSPs. It is
> declared as such in 2 jsps:
> 
>            <jsp:useBean id="monitor" class="java.util.HashMap"
> scope="application" />
> 
>                                                      
> (GalleryViewBottom.jsp
> and Logout.jsp)
> 
>     Now the funny thing is when I issue a
>              monitor.put(request.getRemoteAddr(), session);
> 
> (GalleryViewBottom.jsp)
> 
>     And then try to access it from Logout.jsp the monitor has 
> no such key
> value. Isn't application scope mean its accessable from ANY 
> jsp page? I got
> the ideas for this code from Professional JSP (WROX, pg133 
> checklogin.jsp).

Another way to do this, and better in my opinion, would be to
write a GenericServlet which has a static HashMap member which
gets initialized in init() method and has a static get and
put method.  Configure the servlet as a load-on-startup servlet
and you're ready to go.  Just import the class and do

ClassWhatever.get|put(...);

This will remove lines of code from the servlet generated from your
jsp(autogenerated by the useBean tag).

You could also include remove() and clear() methods.


---
Michael Wentzel
Software Developer
Software As We Think - http://www.aswethink.com