Application scope's duing init()

          hi,
          We have a main servlet, unsuprisingly called "FrontController", where I
          would like to set an application scoped attribute.
          In a jsp, I do thinks like "request.setattribute("a", "b",
          PageContext.APPLICATION_SCOPE)"
          But, I don't have access to the request during the init method of a
          servlet.
          How would I achieve the same kind of thing in a servlet?
          I was thinking that maybe it's possible somehow through the web.xml, or
          weblogic.xml, but have had no luck finding such information.
          Anyone have any ideas?
          dk-
          

init() gets a config parameter. The config has a ServletContext property.
          That is where app-scope attr's are stored:
          public void init(ServletConfig config) {
          config.getServletContext().setAttribute("a", "b");
          Peace,
          Cameron Purdy
          Tangosol, Inc.
          Clustering Weblogic? You're either using Coherence, or you should be!
          Download a Tangosol Coherence eval today at http://www.tangosol.com/
          "denis krizanovic" <[email protected]> wrote in message
          news:[email protected]..
          >
          > hi,
          >
          > We have a main servlet, unsuprisingly called "FrontController", where I
          > would like to set an application scoped attribute.
          >
          > In a jsp, I do thinks like "request.setattribute("a", "b",
          > PageContext.APPLICATION_SCOPE)"
          >
          > But, I don't have access to the request during the init method of a
          > servlet.
          >
          > How would I achieve the same kind of thing in a servlet?
          >
          > I was thinking that maybe it's possible somehow through the web.xml, or
          > weblogic.xml, but have had no luck finding such information.
          >
          > Anyone have any ideas?
          >
          > ___
          > dk-
          

Similar Messages

  • How to init an application scope backing bean once app server startup?

    Hi guys,
    I got an application scope backing bean but I don't know how to initialize it once the app server startup ! I need all the webpage to be able to get the 'defaultCountry' value once the app server startup !
    <managed-bean>
    <managed-bean-name>applicationScopeBean</managed-bean-name>
    <managed-bean-class>com.borneo.webapp.action.ApplicationScopeBean</managed-bean-class>
    <managed-bean-scope>application</managed-bean-scope>
    <managed-property>
    <property-name>defaultCountry</property-name>
                   <property-class>java.lang.String</property-class>
    <value>Singapore</value>
    </managed-property>
    </managed-bean>
    Pls help, Thanks !
    regards,
    Mark

    write a context listener and set up your web.xml as such
    <listener>
    <listener-class>com.package.ContextListener</listener-class>
    </listener>
    Then your class should inmplement ServletContextListener interface.
    The 2 methods need to be implemented
    public void contextDestroyed(ServletContextEvent sc_event) { }
    public void contextInitialized(ServletContextEvent sc_event) { }
    Hope that helps

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

  • OC4J- NamingException: Not in an application scope

    I have a JMS program(ResourceAdapter) which I am deploying on OC4J 10g (10.0.3.0.0) .
    The program first creates InitialContext object and and then looks for the JMS connection factory and JMS queue in the "start" method of resource adapter. When I deploy this program everything works fine first, but later when I bounce oc4j, I start
    getting "javax.naming.NamingException: Not in an application scope"
    exception. Can someone suggest me what could be causing this?
    I have tried restarting the oc4j with userThreads option but it doesn't help.
    Program code:
    try{
    mContext = new InitialContext();
    System.out.println("**************1**********");
    mQueueCF =
    (QueueConnectionFactory)mContext.lookup("ojmsjra/MyQCF");
    System.out.println("**************2************");
    mQueue= (Queue)mContext.lookup("ojmsjra/QUEUE");
    System.out.println("**************3*********");
    }catch(Exception ex){
    ex.printStackTrace();
    After oc4j is restart only "**1**" gets printed and the following exception(lookup fails)
    04/09/27 15:56:15 javax.naming.NamingException: Not in an application scope - start Orion with the -userThreads switch if using user-created threads
    04/09/27 15:56:15 at com.evermind.server.PreemptiveApplicationContext.getContext(PreemptiveApplicationContext.java:29)
    04/09/27 15:56:15 at
    com.evermind.naming.FilterContext.lookup(FilterContext.java:127)
    04/09/27 15:56:15 at
    com.evermind.server.PreemptiveApplicationContext.lookup(PreemptiveApplicationContext.java:48)
    04/09/27 15:56:15 at
    javax.naming.InitialContext.lookup(InitialContext.java:347)
    04/09/27 15:56:15 at
    oracle.panama.messaging.driver.DriverResourceAdapter.<init>(DriverResourceAdapter.java:40)
    04/09/27 15:56:15 at
    sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    04/09/27 15:56:15 at
    sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
    04/09/27 15:56:15 at
    sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
    04/09/27 15:56:15 at
    java.lang.reflect.Constructor.newInstance(Constructor.java:274)
    04/09/27 15:56:15 at java.lang.Class.newInstance0(Class.java:306)
    04/09/27 15:56:15 at java.lang.Class.newInstance(Class.java:259)
    04/09/27 15:56:15 at
    com.evermind.server.connector.deployment.ConnectorArchive.createJavaBeanInstance(ConnectorArchive.java:462)
    04/09/27 15:56:15 at
    com.evermind.server.connector.deployment.ConnectorArchive.start(ConnectorArchive.java:360)
    04/09/27 15:56:15 at
    com.evermind.server.Application.initConnectors(Application.java:444)
    04/09/27 15:56:15 at
    com.evermind.server.Application.postInit(Application.java:681)
    04/09/27 15:56:15 at
    com.evermind.server.Application.setConfig(Application.java:201)
    04/09/27 15:56:15 at
    com.evermind.server.Application.setConfig(Application.java:170)
    04/09/27 15:56:15 at
    com.evermind.server.ApplicationServer.initializeApplications(ApplicationServer.java:1708)
    04/09/27 15:56:15 at
    com.evermind.server.ApplicationServer.setConfig(ApplicationServer.java:1412)
    04/09/27 15:56:15 at
    com.evermind.server.ApplicationServerLauncher.run(ApplicationServerLauncher.java:93)
    04/09/27 15:56:15 at java.lang.Thread.run(Thread.java:536)

    Gedomir,
    Thanks for the reply. But unfortunately it did not work. I was using the default initial context. I tried setting the properties as well. Even then it did not work.
    I am trying this with oc4j_extended.
    Thanks again.

  • BC4J / Struts application scope

    i have one question:
    how can I store objects in an application scope.
    i'd like to store a collection with all users from a viewobject. this collection is used independent from usersessions or requests and can be created when application starts.
    first i tried to achieve it by extending the struts actionServlet and storing it in the servletContext, but i was not able to create ViewObjects in the init-Method of the Servlet.
    Thanks in advance
    Martin

    ServletContext would be the right place to store the information but you'll have to defer the population of your user list until the first session that tries to use it

  • Component in Application Scope and cflock

    Hi,
    I have an CFC that I set in application scope in the
    onApplicationStart method which contains some system parameters,
    one of which is a flag saying whether the site is currently
    "Online". I call a method on this CFC in the Application.cfc
    "onRequest" method to see if the flag value has changed.
    This method looks up a parameter set in the database that
    says whether the site is "online" or "offline". If the site is
    currently online, I want to only redo the query every 5 mins.
    However if the site is offline, I want to check more frequently
    (every 5 secs) as to whether the flag has changed back.
    What I am not sure of, is whether I need to be using
    <cflock> when I change from "online" to "offline"? There is
    only a single instance of this object, but what happens if multiple
    requests are calling the "isSiteOnline" method simultaneously? Is
    this "safe"?
    Some code snippets are attached to illustrate.
    Any advice would be greatly appreciated.
    Regards,
    Andrew.

    > <!--- DO I NEED TO USE CFLOCK HERE???? --->
    No, in either situation.
    Ask yourself... what would the ramifications be of two
    requests hitting
    that line of code "simultaneously"? The end result is that
    both of them
    are setting the variable to the same static value... so
    that's what's going
    to end up happening: variables.instance.cacheInterval is
    going to be set to
    300 (or 5) in each situation.
    You could well with to lock a block of code which - if called
    simultaneously via more than one request - could act on
    shared storage
    space (server, application or session data) differently and
    incorrectly
    than is intended.
    eg:
    <!--- application bootstrap process --->
    <cfif not structKeyExists(application, isInitialised and
    not
    application.isInitialised>
    <!--- initialisation process, whatever it is --->
    <cfif allOK>
    <cfset application.isInitialised = true>
    <cfelse>
    <cfset application.isInitialised = false>
    </cfif>
    </cfif>
    So a sequence of events could be (say the user is hitting the
    site with two
    different browsers):
    REQUEST1: application.isInitialised doesn't exist
    REQUEST1: starts the init process
    REQUEST2: application.isInitialised STILL doesn't exist
    REQUEST2: starts the init process *again*
    REQUEST1: sets the application.isInitialised value
    REQUEST2: sets the application.isInitialised value
    Obviously one does not want two request running the
    initialisation code.
    note this is a slightly contrived example, as if one has an
    OnApplicationStart() method, then it will only run once, and
    that's where
    one would have the init code, but it demonstrates the issue.
    Google "race condition". Those are the situations in which
    one needs to
    lock blocks of code.
    Adam

  • Calling a method for application scope

    I have a method that initializes a hashtable.
    That method should be called once when my web app starts, I need to load that hashtable into memory so whenever a user needs a value from that hashtable, it readily access the hashtable and doesn't load it everytime it is called. How do I do that?

    Just put it in the application scope in the faces-config.xml?

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

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

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

  • Application scope problem in a JSP

    Hi,
    I try to store an object with the following code :
    getServletContext().setAttribute("application", app);
    Later I want to access this object from a JSP with :
    <jsp:useBean id="application" scope="application" class="de.skillworks.SWApp"/>
    that dosn't work !? I can not debug my application because the jsp is initializing my app object new. When I try in my JSP :
    SWApp app = (SWApp)pageContext.getServletContext().getAttribute("application");
    it works fine. I get my object which I have store in my servlet.
    In a Tomcat environment my code is working just the Jdeveloper has a problem with it.
    null

    Andy -
    The web-to-go server has difficulty dealing with sessions. Testing in Tomcat is a good alternative, and this is resolved in Oracle9i JDeveloper.
    Hope this helps,
    Lynn

  • Best Performance? - having a single stateless java pojo as delegate- give it application scope?

    I'm curious about which is best from a performance standpoint -<br /><br />All of our flex calls access a single java pojo. In my remoting-config.xml I'm currently declaring the destination a property scope of 'application': <br /><br /><destination id="UIServicesDelegate"><br />    <channels><br />      <channel ref="my-amf"/><br />      <channel ref="my-local-amf"/ <br />    </channels> <br />     <properties><br />        <factory>spring</factory><br />        <source>uiServicesDelegateBean</source><br />        <scope>application</scope><br />    </properties><br /></destination><br /><br />All of the UIServiceDelegate methods are stateless however, so I'm wondering if I'm gaining anything by giving it scope session. Since their all stateless I"m assuming application scope would be the best from a performance standpoint? I'm assuming in this case only one object will ever be instantiated? <br /><br />Assuming it was between Session and Request scope, is there a lot of overhead instantiating the new server side object each time? I would assume performance would be better using the Session in this case, with the only draw back of some server-side ram being chewed up storing the object in the Session. <br /><br />If you want "singleton" type approach, I figure just using application scope is the preferred approach?

    You wont get any api for directly accessing Servlet application objects from any ejb. I dont think MDB either solves your problem directly. Indirectly you can place a request to some servlet (should be there for each JVM and web application ) and update your application scope variable. I would suggest you to cache the data in database if the size of cache is large. otherwise any open caching tools may help you.

  • Accessing Application Scope from an EJB

    I'm not sure of the best way of doing this:
    The set up:
    We have a rather large J2EE application that is composed of only servlets and JSPs at the moment (When the application began development EJB was in its infancy and not feasible for the development of the app). Some of the new deployments of the app involve distributed webserver over 4 JVMs and 2 machines. When a user connects the servers load balancing decides which particular JVM they should be connected to. We perform large data caching into the servlet application scope to avoid having to access the database every time a change is made by a user to certain tables in our database. The data caches are stored in hashtables in the servlet application scope.We seem to have no way to determine what other JVMs are running or which JVM a user is currently connected to.
    The problem:
    Apparently the application scope is for a particular JVM. This means that when a user makes a change to a data cache the change doesn't effect users in the other 3 JVMs of the application, only the users who, due to load balancing, happened to be connected to the same JVM as the one where the change was made.
    Our possible solution:
    We were thinking that we could set up a queue (such as MQSeries from IBM) and any time a change is made to one of these data caches put a message on the stack saying that the particular table had been updated. Then a MDB would be listening asynchronously and digest the message from the Queue and recache the tables from the database.
    So here are my questions:
    1. Would this work? Would putting a MDB in the EJB Container give each JVM the MDB in the first place, or would this mean it would pick one of the JVMs to deploy the MDB on and still not fix our problem.
    2. If this does work, how do I access the hashtables stored in the Servlet Application scope from the MDB. I can't seem to find any method available to the MDB (or any EJBs for that matter) that can access the servlets Application scope.
    3. Is this the best way to do this? Or is there a better way to share data between seperate JVMs that I don't have a URL to (It's all ambiguous and handled by the server as to which JVM actually gets the connection.)
    Just in case this is needed:
    We are running IBM WebSphere 5 Application Server and the database could be anything from DB2 to Oracle.
    Thanks in advance for any possible help.

    You wont get any api for directly accessing Servlet application objects from any ejb. I dont think MDB either solves your problem directly. Indirectly you can place a request to some servlet (should be there for each JVM and web application ) and update your application scope variable. I would suggest you to cache the data in database if the size of cache is large. otherwise any open caching tools may help you.

  • 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

Maybe you are looking for