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");

Similar Messages

  • How to implement use bean tag in servlet technology

    hello,
    i want to use application scope for variables in application . i know about use bean tag but i want to use servelet technology. how could this be done

    The application scope corresponds to the servlet context. From your servlet, use getServletContext().getAttribute() and getServletContext().setAttribute().

  • How can a session scope bean access an application scope bean - help

    Hello,
    I have a JSP page that has references to an Application Scope and a Session Scope bean...
    <jsp:useBean id="myWebApp" scope="application" class="com.my.web.WebApplication" />
    <jsp:useBean id="myWebSession" scope="session" class="com.my.web.WebSession" />
    I would like the WebSession access methods in the WebApplication ... Can/ How does the WebSession object lookup the reference to WebApplication object?

    I don't think you should make the WebSession implement the session listener.
    The session listener will be created once, at the start of the servlet context and would be listening to all sessions. So you would have one instance of the WebSession belonging to the context (though not as an attribute), and others belonging to each session. This will be confusing in your code, I think.
    I would suggest having a different class act as the HttpSessionListener. Perhaps do something like this:
    public class WebSessionInjector implements HttpSessionListener {
      public void  sessionCreated(HttpSessionEvent e) {
        WebApplication webApp = (WebApplication)(e.getSession().getServletContext().getAttribute("webapp"));
        WebSession mySession = new WebSession();
        mySession.setWebApplication(webApp);
        e.getSession().setAttribute("mySession", mySession);
      public void sessionDestroyed(HttpSessionEvent e) { ... }
    }You may be able to use the WebApplication object itself as the listener ...
    Or, you could make the WebSession implement the HttpSessionBindingListener and use the valueBound event much like the sessionCreated event above, but from inside the WebSession object:
    public class WebSession implements HttpSessionBindingListener {
      public void  valueBound(HttpSessionBindingEvent e) {
        WebApplication webApp = (WebApplication)(e.getSession().getServletContext().getAttribute("webapp"));
        this.setWebApplication(webApp);
      public void valueUnbound(HttpSessionBindingEvent e) { ... }
    }

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

  • Implement SSL in JSP and servlets

    hi there,
    i needed some help in implementing ssl in JSPs and servlets. My idea was to have a login page and also use it where sensitive data is being sent. I have used the basic socket programming (socket.class and serverSocket.class) in GUI applications using threads to listen and send simultaniously and understand how it works but how do I implement it in JSP and servlets and where do i store the certificate?
    i do know that using SSL sockets is very much the same as using the normal sockets.
    can anyone tell me any useful links or give me a step by step guide how to implement it and which classes to use
    your help would be very much appreciated.
    mani

    hi,
    soory for late reply.
    i think you need to use keytool program in your JDK to generate a certificate signature file and you need to configure the server.xml to open and use the HTTPS port. I have not had any additional info on this but i would assume that you simply enter https:// on the file you wish to load in your form and it should use the HTTPS port provided it can find the certificate which must be stored somewhere in your tomcat web server. i would recommend you see tomcat website or search on google for "ssl support in tomcat".i hav not had time to look into this but i will as soon as i am free from my work load.
    mani

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

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

  • Initializing application scope beans on startup

    Hi All,
    I need to initialize an application scope managed bean on startup, and not have to wait for it to be referenced the first time.
    I was thinking of using ContextListener, but you dont have access to the faces context in the listener.
    And you cant even extend FacesServlet, since its final.
    Any ideas on how this can be achieved.
    Thanks for your help!!

    Try with FacesContext.getCurrentInstance() or http://www.jsffaq.com/Wiki.jsp?ptitle=How+to+access+FacesContext+from+the+Filter+or+Servlet%3F&page=HowToAccessFacesContextFromTheFilterOrServlet

  • Application Scope Objects and Multithreading

    I will be creating a set of interlinking objects in application scope that are intended for read only. The objects will be accessed every time a user makes a request to the servlet which will be on every link of the site since the servlet is a controller.
    I am pretty sure that there are no concurrency issues here - that all requests will be able to access the objects quickly. Can someone confirm this for me.

    As long as the threads only read information from the objects and do not update them then you should be ok.

  • 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

  • ACCESSING APPLICATION SCOPE FROM FILTERS

    HI
    Is there any way to access the application scope from inside security filters? i have a class that implements the Filter interface and i'm trying to access the application scope in the doFilter method.
    The FacesContext Object is null, and i'm only able to access the session scope using request.getSession()
    I want to check for global application properties that are saved in the application scope.
    Thanks

    thank you BalusC it's working

  • Storing int variable in application scope

    hi all,
    I have a requirement where i need store some counter(int) in the application scope. Please tell me how to do that. I know create instance of userbean in application scope, but how to do for integer. Thanks in advance.
    -Manjunath

    Hi,
    you can only store Java Objects in the various scopes. you cannot store the primitive data types. so convert the integer to Integer Object and then store that one using setAttribute. Dont forget to parse the retrieved object to Integer as you will get Object type.
    do this:
    int i=10; //you have
    Integer j = new Integer( i );
    request.setAttribute("name", j );
    Integer k =(Integer)requst.getAttribute("name");Hopes this will help you.
    Prasad Babu Dandu,
    BOB Technologies,
    Bangalore

  • 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
              

Maybe you are looking for

  • I have two Apple ids and I want to unify them under one i.d.  How do i do that?

    I have two Apple I.D.s and want to unify them under one i.d.  How do I do that?  I called the Apple support line and the technical representative told me to contact you.

  • Need Help With Drivers for 488ca

    Hi I'm having nothing buy trouble I have a designjet 488ca and for the life of me can't down lode the soft ware they no longer make the CD and this thing is just keep going around with the same old crap I would be glad to pay for the CD if they just

  • How to Position of a dynamically created child symbol.

    Hello Everyone, I created symbols instances on the stage by for(alpha = 0; alpha < 5; alpha++)     sym.createChildSymbol("rect", "Stage"); Now I wanted to set the position of each symbol  - The probelm is I don't know the names of the symbols instanc

  • Linux on Parallels, worth trying?

    I have the standard 17" 2.0 Ghz Core 2 Duo 1 gb iMac. I'm interested in trying to use some Linux apps in Parallels desktop, but I'd really appreciate some advice before I dive into something that may be over my head! 1) Do I need to upgrade to 2 Gigs

  • Only 1 Ear Bud Will Work

    I can only get one ear bud to play. I tried several different pairs (all of which work fine on my son's Nano) and still I'm stuck with mono. Any ideas? Thanks! Message was edited by: MeritaC