Destroy in JavaBean with application scope?

Hi,
I am using a java bean in my jsp application with scope "application". I know that this java bean will be terminated only when the server stops or shuts down (Apache Tomcat 5.5).
I need to cleanup something manually when the server shuts down. Can anyone tell me what method will be called, or that I can override, to clean up?
I tried finalize and valueUnbound (implements HttpSessionBindingListener) with no luck... I just can't find a equivalent to destroy in Servlets (I can't use servlets, must use javabeans+jsp)...
Any sugestion?
thanks in advance for your time

There is an indirect way if you know servlets. The "application" implicit object that you use in your JSP is the javax.servlet.ServletContext object. Instead of declaring your bean using the jsp:useBean tag, directly put your objects into the ServletContext using ServletContext.putAttribute() method. Objects put in the ServletCOntext are available to all pages in the application. Just use the ServletContext.getAttribute() method to retrieve this bean in any other page.
To "kill the bean", just reset the value of this object to null by calling putAttribute(null).

Similar Messages

  • Killing a bean with application scope?

    Is there any way to kill a bean with application scope?
    I am writing a web application, that most likely the browser window will never be closed. The problem is a user is authenticated onto our site but because the bean containing the users acct info is application scope, if another user logs in it still shows the old user as logged in. So on logout i would like to kill the application, the bean, servletContext...anything that will refresh the bean and the corresponding jsp. Any help is much appreciated.

    There is an indirect way if you know servlets. The "application" implicit object that you use in your JSP is the javax.servlet.ServletContext object. Instead of declaring your bean using the jsp:useBean tag, directly put your objects into the ServletContext using ServletContext.putAttribute() method. Objects put in the ServletCOntext are available to all pages in the application. Just use the ServletContext.getAttribute() method to retrieve this bean in any other page.
    To "kill the bean", just reset the value of this object to null by calling putAttribute(null).

  • How to use a JavaBean with request scope from one page to other page

    Hi,
    I want to use in one jsp file a javabean with scope of request for it, I use:
       <jsp:useBean id="entry" class="jsps.SaleEntry" scope="request" />and after in that page I make operations with it using the jsp:setProperty and jsp:getProperty operations
    My question is that if I want to get the result of that javabean in the following page, Have I to record the javabean doing : request.setAttribute(""objectId",id) and then in the following jsp page I can rescue the object doing: SaleEntry sE=(SaleEntry) request.getAttribute("objectId") ???
    or in the contrary, only using jsp:setProperty the information is available to recover it in the following jsp doing : SaleEntry sE=(SaleEntry) request.getAttribute("objectId") because setProperty records the information without need of doing : request.setAttribute(""objectId",id). ????
    Thanks with anticipation and sorry if it is a silly question but I am beginner in the use of JavaBeans

    Thanks Anthony,
    I'm working with Tigi on the same project and now I can tell you that the problem is solved.
    request.getRequestDisptacher("/myServlet");hehe, you switched the 't' and the 'a'
    <%@ include file="/myServlet" %>this is the one we use :)
    But what is the difference between the first one and the last one? Now We are using the last one because that's the shortest :) not a pretty good reason huh :)
    cheers,
    Soep

  • Application scope bean Vs. EJB

    I want to cash some application data - and was thinking of using a singleton bean with application scope in my controller and JSP page.
    <jsp:useBean id="myBean" scope="application" class="bean.datacash" />
    I am not very familiar with EJBs - and wanted to know if it would be a mistake not to use an EJB to perform that task.
    Is there a downside to my approach?
    Thanks for any insight
    Mike

    Entity EJB'S are used as a kind of data persistence, mostly to Databases. In a way it's like a kind of cache but any changes you make to an EJB are usually persisted to the underlying data storage on a regular basis.
    Session EJB's are more for business logic and depending on the type of Session Bean you use can either remain persisted in a session state or used and thrown away.
    EJB's also require alot of code so depending on your application requirements it is kind of a big decision.
    Is the data your wanting to cache to be shared by all users using the application? Are there any race conditions that may be met by concurrent access to the data? What do you plan to do with the cached data store it in a database or just make it available to share?
    If you want to look into using EJB's then your going to require an EJB Container to run them in (this can be standalone like OpenEJB or as part of an J2EE Application server like JBoss or Oracle Application Server to name just a couple).
    Using the Singleton Javabean can keeps things simple but once you start to synchronize methods with multiple users you can find some slowing down of the logic as the singleton tries to complete a request before getting onto the next.
    The [url http://jakarta.apache.org]Jakarta team offer a package called commons pooling which is designed as a pooling framework (also a way of caching) that can come in handy, I've used it to create a custom JDBC Connection pooler and it works quite well when you get the hang of it.
    Another thing to consider is the load the application may be under at it's busiest time. How many concurrent users do you expect to access the application?
    Sorry I can't give you a real answer as that is entirely up to you and your requirements. If you have a small app that has around 20-50 users then EJBs are bit of an overkill. If you find you'll have 100+ users with lots of data to manage then EJB's are probably a good option.
    If you have a look at [url http://www.theserverside.com]the serverside web site you may find a couple of articles on data persistence or check out some of the online magazines which also have articles on this same topic.
    Anthony

  • Objects of application scope and clustering.

              I understand that weblogic 6.1 replicates session data to a secondary server in a
              cluster. This replication should include objects declared with <jsp:useBean ...
              scope="session"/> as well as objects that are explicitly maintained in the session
              with setAttribute().
              However, what about objects with application scope? Are they replicated to a secondary
              server when a cluster is in use?
              Thanks,
              -Dave.
              

    David Vazquez <[email protected]> wrote:
              > I understand that weblogic 6.1 replicates session data to a secondary server in a
              > cluster. This replication should include objects declared with <jsp:useBean ...
              > scope="session"/> as well as objects that are explicitly maintained in the session
              > with setAttribute().
              > However, what about objects with application scope? Are they replicated to a secondary
              > server when a cluster is in use?
              No, they are not replicated in the cluster. To implement replication you can use JavaGroups:
              http://sourceforge.net/projects/javagroups/ or Cameron's Coherence product:
              http://www.tangosol.com/products-clustering.jsp for example.
              > Thanks,
              > -Dave.
              Dimitri
              

  • Implementation of application scope in servlet technology

    hello,
    i want to define certain variable with application scope , in servlet technology how to do that

    Attributes can be stored in the ServletContext in the same manner as they are stored in the session.
    String x = "Stored Value";
    getServletContext().setAttribute("x", x);
    String y = (String) getServletContext().getAttribute("x");

  • Facing error as Not in an application scope - start Orion with the -userThr

    hi all,
    iam facing this error when an jsp which is in Oracle portal(emebedded in iframe code) is updating a flag in database through a datasource configured on portal side.
    Naming Service=Not in an application scope - start Orion with the -userThreads switch if using user-created threads
    regards,
    Ravi

    I encounter the same issues when using the TimerTask to access the JNDI tree. I have found success when I move my business logic to an EJB and call my EJB from my TimerTask. It's a bit more work, but not much. The EJB inherits it's identity based on it's configuration and has no trouble accessing the JNDI tree whenever it's called. Try this and see if your problem doesn't go away.
    Hope this helps,
    Perry Tew

  • Scope when using a JavaBean with JSP

    what is the meaning of this question .....?
    "Which of the following can not be used as the scope when using a JavaBean with JSP? "
    question 4
    site :http://java.sun.com/developer/Quizzes/jsptut/

    The question is clearly written. I don't see how you can be confused. But let's assume you are since you would not have posed the question.
    Dumbed-down:
    There are 4 scopes or areas of variable visibility in JavaServer Pages. Which of those can areas can not be used with JavaBeans?
    Does that help?

  • Using Application Scope Javabean to hold data?

    I have a set of (4000) records I would like to store in a Javabean to be used within mutiple JSPs. I am using JSP and Javabeans, no EJBs. My question is should I use Application scope for the Javabean to be shared for all the JSPs instead of a Sesstion scope to limit stress to the server? Thanks.

    I think use session scope. Application scope may tie up resources u might not need. That is my personal opinio though.

  • Problem with application-variables - CFLOCK?

    Hi,
    i have a problem with my application. It is a multi-user
    application with 100 parallel-users and CFMX 7.
    The problem wich occures is with application variables. These
    are mainly structs wich get filled onApplicationStart(). The
    problem is, that the variables suddenly disappear, they are empty.
    I have read about CFLock and found out, that it is necesseary
    to use cflock. And i found out, that onApplicationStart does
    correct locking automatically. That is where i do not understand
    the problem. The variables get intialized correctly and in further
    they only get read-access. Why can they be corrupted?
    My other question about that is, wheather i need cflock for
    all Read-Access to Application and Session-Variables, even if there
    happens no writing to the variables?
    Best Regards,
    Andreas

    > ?The element of position 2, of dimension 2, of an array
    object used as part of
    > an expression, cannot be found.?
    > The array is in this case the struct.
    Well, OK, that could be a problem. Arrays are not structs:
    they are two
    different things, are not interchangeable, and have
    completely different
    sets of functions to utilise them. You cannot treat a struct
    as an array.
    If CF is claiming your "struct" is an array, then it actually
    *is* an
    array, not a struct.
    What's the line of code which is generating that error?
    I suppose one could get this error if you have an array of
    structs thus:
    myArray
    .key1
    myArray.key2
    (etc)
    and you're trying to reference it with a numeric key rather
    than by key
    name, eg:
    myArray
    [n]
    When n is an integer value, rather than a string (which
    corresponds to the
    name of the key).
    > > Have you trapped the error, done a <cfdump>
    of the application scope and
    > > checked to see if it's the whole lot going awry, or
    just some values?
    > I have not used cfdump for it, because the server had to
    be immediately
    > restarted for our customers. But i think, that it is
    not completely empty,
    > because the index runs to pos2 of dimenstion2.
    So does this not happen in your dev / testing environment?
    > Will
    > onApplicationStart() be called before? Or only if
    onRequestStart() returns true?
    I would ***-u-me that the application one would be called
    before the
    request one. It's pretty easy for you to test this though, I
    should think?
    (Sorry: for reasons beyond the scope of this conversation,
    we're still
    forced to use Application.cfm in our software, so I've only a
    passing
    knowledge of how Application.cfc works).
    > Here is the code from onRequestStart()
    > <cffunction name="onRequestStart"
    returntype="boolean">
    > <cfargument name="Requestedpage" required="yes" />
    > <cfscript>
    > var lFile = "/cargorent/Login.cfm";
    > var iPosn = ListFindNoCase( lFile,
    Arguments.Requestedpage );
    > if( iPosn gt 0 )
    > return true;
    >
    > if( NOT IsDefined( "session.user.Loginname" ) or
    session.user.Loginname eq
    > "" )
    > {
    > WriteOutput( "<p><p> The current user is no
    longer valid, please log in
    > again.</p></p>" & chr(10) & chr(13)
    > WriteOutput( "<script
    language=""javascript"">parent.location = ""
    http://"
    > & CGI.HTTP_HOST &
    "/Login/Login.cfm"";</script>" );
    > return false;
    > }
    >
    > return true;
    > </cfscript>
    > </cffunction>
    One thing I will say here is that I really think you should
    be separating
    your processing from your display. A function should do
    processing. it
    should pass that processing back to a CFM template which
    should handle
    whatever needs to be displayed on the browser. Although
    that's nowt to do
    with your current issue.
    Adam

  • What are the pros and cons of storing heavely used CFCs in the application scope?

    I've been storing all the required CFCs for a site in the application scope. During onApplicationStart I do something like this application.objSomeCfc =CreateObject('component', 'com.someCfc').init().
    Here is my reasoning.
    Get the CFCs initialized once and stored in memory for better performance.
    Using CreateObject several times on each page load can have a negative impact on performance.
    Having one place to create application scoped CFCs makes it easier to manage code.
    So is my thinking flawed? Are there any additional pros or cons for dealing with CFCs? Is there any docs, articles, blogs, videos, frameworks, ...... that I should check that may change my perspective on how I'm doing this?
    Thanks

    Your approach is fine, depending on how many and what type of CFCs you are talking about. If they are "singletons" - that is, only one instance of each CFC is needed to be in memory and can be reused/shared from multiple parts of your application - caching them in the application scope is common.  Just make sure they are thread safe ("var" or local.* all your method variables).
    You might consider taking advantage of a dependency injection framework, such as DI/1 (part of the FW/1 MVC framework), ColdSpring, or WireBox (a module of the ColdBox platform that can be used independently).  They have mechanisms for handling and caching singletons.  Then you wouldn't have to go to the application scope to get your CFC instances.
    -Carl V.

  • Looking for best practice on application scope beans

    Hey – a portal newbie here. I’ve got some application scope beans that need to be initialized on startup. First thought was to create a servlet that would set the bean. Then I saw the GlobalApp setting, but I think that looks like it is more session scope than application… Looking to be corrected here if I am wrong.
    Is there a place where these type of things traditionally happen? Read only, so no cluster worries (I think) Using WLP 8.1 SP4 and looking for best practices. Thanks for the help!

    To support "code sharing" you need an integrated source code control system. Several options are out there but CVS (https://www.cvshome.org/) is a nice choice, and it's completely free and it runs on Windows, Linux, and most UNIX variants.
    Your next decision is on IDE and application server. These are usually from a single "source". For instance, you can choose Oracle's JDeveloper and Deploy to Oracle Application Server; or go with free NetBeans IDE and Jakarta Tomcat; or IBM's WebSphere and their application server. Selection of IDE and AppServer will likely result in heated debates.

  • Updating Beans in Application Scope

    The problem is that i dont know how to update a bean in an application scope:
    in EA4 i use this instruction to update a bean property:
    // get the faces context
    FacesContext facesContext = FacesContext.getCurrentInstance();
    // update a property in application scope
    (Util.getValueBinding("BeanName.propertyName")).
    setValue(facesContext,"text");
    and it worked ok in jsp:
    <h:output_text valueRef="BeanName.propertyName" />
    Now in version 1.0 i wrote:
    Application app = facesContext.getApplication();
    errorAplicacion = (ErrorAplicacion)app.createValueBinding("#{beanName}").
    getValue(facesContext);
    How should i update this value in application scope to be used in the jsp ?
    I use in jsp:
    <h:output_text value="#{BeanName.beanProperty}"/>
    But i receive in logs:
    Expression BeanName.beanProperty does not follow the syntax #{...}
    And the result is null
    Thanks a lot
    German

    If you are quoting your 1.0 code literally, you've got a case mismatch between "#{beanName}" when you create the value binding expression and "#{BeanName}" in the JSP page. As with most things in Java, the names are case sensitive.
    Craig McClanahan

  • 300 requests per hour reading from Application scope Good/Bad idea

    I am saving some html in application scope & reading with
    <cflock readonly.
    Will it be a problem if more than 5 requests are made per
    second?
    Does deadlocks occurs with readonly-cflock?
    Thanks

    While creating/changing application scope variables in a
    lock, I think there must be an exclusive lock. You must be careful
    not to set any shared variable such as application inside a read
    only cflock tag.
    I also would suggest to check the usage of Application.cfc
    and onApplicationStart method. You can set application default
    variables and constants in onApplicationStart method in your
    Application.cfc.

  • Share stateful session bean in JSF managed beans with different scope

    Hi,
    I have a JSF application and I want to try to use of stateful session beans.
    So I created a new stateful session bean and its local interface.
    @Stateful
    public class StatefulSessionBean implements StatefulSessionBeanLocalInterface{
    private String name;
    @Local
    public interface StatefulSessionBeanLocalInterface {
    ...In my JSF application I have a mananed bean with session context which registers the new interface by
    this annotation
    @EJB(name="sessionbeanref", beanInterface=StatefulSessionBeanLocalInterface.class) and set the name to something.
    Now I want to fetch this name in another managed bean with request scope. So I looked up the bean and tried to get the name.
    StatefulSessionBeanLocalInterface = (StatefulSessionBeanLocalInterface) new InitialContext().lookup("java:comp/env/sessionbeanref");
    System.out.println(currentmailingbean.getName());but the name is null.
    Why?

    The xsd was created via the netbeans J2EE enterprise application dialog and I think its the most recent.
    <?xml version="1.0" encoding="UTF-8"?>
    <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">All other annotations seem to work.
    Wouldnt the lookup completely fail if the deployment process thought that it is version 1.4 ?

Maybe you are looking for

  • Greyed out loops in Garageband 11?

    I installed GB11 from the Mountain Lion's Appstore and not from an iLife DVD. It required an update for the loops and most of them downloaded but there are still some greyed out buttons. Here's a pic: http://imgur.com/5OgugCL All the support pages an

  • Transfering music from new iMac to iPod without losing songs on ipod

    Hello, I've just finised uploading all my CD's onto my new iMac. I now wish to download the contents of the iMac's iTunes library onto my iPod (click wheel but not video) without losing the songs that are already on the iPod. The iPod was originally

  • How do I open a new url after a flv finishes playing?

    Sorry for asking this question again, but I'm under the gun. I have a get url action script command in my movie in the frame after an FLV. It doesn't work. What's the trick to triggering a getURL command when an FLV finishes? Thanks.

  • Broken link to download Indesign CS3 - can anyone help me download it?

    I had my Mac reset, but it won't accept the backup file I made of Indesign CS3. I looked online and tried to download Indesign CS3 from these two links, but keep getting this error message: Download CS3 products http://www.adobe.com/uk/downloads/othe

  • Help! Internal error application 'conversations cl...

    hi i got a text message from a friend and when i opened it up an error message showed up: internal error. Application 'conversations closed'. this means i cant read her sms or send any sms at all to anyone. anyone know how to fix, maybe a command in