Can a bean access ServletContext?

Hi!
Please help me!
I put initial beans to ServletContext in my servlets init() method.
How can I get this beans (app scope) from another bean (session scope)?
Can I reach ServletContext from a class that is not a servlet?
Thaks!

Please help me!
I put initial beans to ServletContext in my servlets
init() method.
How can I get this beans (app scope) from another bean
(session scope)?
Can I reach ServletContext from a class that is not a
servlet?Not in a normal JavaBean. You can do it with custom tags, but I guess that is not what you want.
What you would have to do is create a setter method for the Bean:
//This is part of the bean in session that requires access to one in servlet context
public class SessionBeanClass ...
  private ServletBeanClass otherBean;
  public void setOtherBean(ServletBeanClass sbc) { otherBean = sbc; }
  public void getSomethingThatReliesOnOtherBean()
    if (otherBean == null) throw IllegalStateException("This Something can not be done until an object of type ServletBeanClass is assigned.");
    // rest of method
}Then in the servlet you would need to assign the correct value, preferrably when the bean is first created.
// somewhere in your servlet
    SessionBeanClass sessionBean = new SessionBeanClass();
    sessionBean.setOtherBean((ServletBeanClass)getServletContext().getAttribute("otherBean"));Or if you are using a JSP:
<jsp:useBean id="sessionBean" class="my.package.SessionBeanClass" scope="session">
  <jsp:setProperty name="sessionBean" property="otherBean" value="${servletContext.otherBean}"/>
</jsp:useBean>

Similar Messages

  • Can beans access ServletContext?

    I want to use my web deployment descriptor (web.xml) to store database connection parameters. Unfortunately, the only way that I know how to access the ServletContext is through the request.getServletContext() method. Since my bean classes don't have a handle on the request object, how can I access the ServletContext to get this information?
    Any good practice advice from anyone?

    Right but I have a bean that I want to have access the servletcontext. From the bean class itself. (not the setProperty tag in JSP).

  • Remote Delta link setup problem with Bean / Access Service

    Hello,
    I am trying to setup Remote Delta Link (RDL) between two portals. (Both portals same version - EP 7.0 EHP1 SP 05 - are in the same domain)
    I already have the Remote Role Assignment working without any issues.
    The following have been done successfully:
    1. Same user repository has been setup for both the portals
    2. Setup trust between producer and consumer (SSO working fine)
    3. Producer added and registered succesfully on consumer
    4. Permissions setup on producer and consumer
    4. pcd_service user with required UME actions setup
    I am able to see all the remote content in the Consumer portal.
    When I try to copy the remote content and paste it as local content, I am getting the following error:
    Could not create remote delta link to object 'page id'. Could not connect to the remote portal. The remote portal may be down, there may be a network problem, or your connection settings to the remote portal may be configured incorrectly.
    After increasing the log severity, I am able to see the following in Default Trace:
    com.sap.portal.fpn.transport.Trying to lookup access service (P4-RMI) for connecting to producer 'ess_int' with information: com.sap.portal.fpn.remote.AccessServiceInformation@31c92207[connectionURL=hostname.mycompany.com:50004, shouldUseSSL=false, RemoteName=AccessService]
    com.sap.portal.fpn.transport.Unable to lookup access service (P4-RMI) with information: com.sap.portal.fpn.remote.AccessServiceInformation@31c92207[connectionURL=hostname.mycompany.com:50004, shouldUseSSL=false, RemoteName=AccessService]
    AbstractAdvancedOperation.handleDirOperationException
    [EXCEPTION]
    com.sap.portal.pcm.admin.exceptions.DirOperationFailedException: Could not retrieve the bean / access service to connect with producer
    Could not retrieve the bean / access service to connect with producer
    Like you can see above, there is some bean / access service which is not retrieved successfully. I am not sure if this is a permission problem on the consumer.
    I have checked that the P4 ports are configured correctly (standard - not changed) and I am able to telnet from producer to consumer (and vice versa) on the P4 port.
    I am stuck at this point and am not able to find any information on this.
    I would really appreciate if some one can point me in the right direction.
    Thank you for reading.
    - Raj

    Hi Raj,
    Please check your config of the P4 port on the producer.  Is it really 50004 (check SystemInfo of the producer)?
    I do think there's a problem with the P4 communication since RDL requires P4 connection.
    Do you have load balanced consumer-producer connection? Please refer to this blog for further details
    Little known ways to create a load balanced Consumer – Producer connection in a FPN scenario
    Regards,
    Dao

  • Can BI Beans be used on JBuilder 4?

    Can BI Beans be used from the JBuilder 4 IDE together with the Oracle 9i database? Are there any special requirements to get that set up?
    thanks.

    BI Beans are standard Java Beans, and can be used with other Java IDEs than JDeveloper. However, you will not have the advantage of the JDeveloper integration, UI customizers, live access to OLAP data, wizards etc.

  • JMX - Accessing ServletContext in an MBean implementation

    How do you access the ServletContext from a class that implements an MBean interface? My application stores logs in application scope (ServletContext) and I need to access those logs from my MBean implementation.
    public class Stats implements StatsMBean {
    // How do I access ServletContext here?
    }Any ideas?

    How aboutpublic class Stats implements StatsMBean {
      private ServletContext context;
      public Stats(ServletContext context) {
        this.context = context;
      // some methods that can now use the "context" variable.
    }

  • Can't serialize access for this transaction error.

    Hi,
              I am getting a transaction rolled back due to a beforeCompletion exception:
              java.sql.SQLException: ORA-08177: can't serialize access for this
              transaction
              I am using Weblogic 5.10, SP5 & Oracle 8.
              Basically what I have is:
              - A java app that will get an EntityBean, named Schedule.
              - The java app will then create a SessionBean, named Watchdog.
              - The java app will then call a method on the Watchdog, passing in the
              Schedule: watchdog.check(Schedule sched)
              - The watchdog.check() method will do some processing and based on the
              outcome may or may not update the Schedule: sched.setLast(<some number>)
              - The check() method is then done & return to the java app.
              I see log messages (on the weblogic server) saying the check() method is
              done. Then I see messages, presumably from the container for:
              - isModified ------> true
              - ejbStore()
              And then I see the exception messages.
              The strange thing is that most of the time this processing works just fine.
              Only occasionally do these exceptions get thrown.
              The schedule EntityBean is set up as <transaction-isolation> for
              TRANSACTION_SERIALIZABLE.
              There is no other bean trying to update the Schedule at the same time.
              Does anybody have any ideas?
              Thanks in advance,
              Beth
              

    http://www.weblogic.com/docs51/classdocs/API_ejb/EJB_environment.html#107296
              8
              tells u about the limitations of transaction_serializable w.r.t. Oracle..
              Pavan
              "Beth" <[email protected]> wrote in message news:[email protected]...
              > Hi,
              >
              > I am getting a transaction rolled back due to a beforeCompletion
              exception:
              > java.sql.SQLException: ORA-08177: can't serialize access for this
              > transaction
              >
              > I am using Weblogic 5.10, SP5 & Oracle 8.
              >
              > Basically what I have is:
              > - A java app that will get an EntityBean, named Schedule.
              > - The java app will then create a SessionBean, named Watchdog.
              > - The java app will then call a method on the Watchdog, passing in the
              > Schedule: watchdog.check(Schedule sched)
              > - The watchdog.check() method will do some processing and based on the
              > outcome may or may not update the Schedule: sched.setLast(<some number>)
              > - The check() method is then done & return to the java app.
              >
              > I see log messages (on the weblogic server) saying the check() method is
              > done. Then I see messages, presumably from the container for:
              > - isModified ------> true
              > - ejbStore()
              > And then I see the exception messages.
              >
              > The strange thing is that most of the time this processing works just
              fine.
              > Only occasionally do these exceptions get thrown.
              >
              > The schedule EntityBean is set up as <transaction-isolation> for
              > TRANSACTION_SERIALIZABLE.
              > There is no other bean trying to update the Schedule at the same time.
              >
              > Does anybody have any ideas?
              > Thanks in advance,
              > Beth
              >
              >
              >
              >
              

  • Concurrent entity beans access

    I have failed to come up with a workable solution for concurrent entity bean access on the SUN reference implementation together with cloudscape.
    I have created a test case and a webpage which describes my problem. If anyone can come up with a working solution (must work on the RI) I would be very thankful.
    Please have a look at
    http://www.offermanns.de/~rolf/ejb-concurrency/
    and tell me what you think.
    -Rolf

    Hi,
    I thought that this is a problem. But this isn't just
    about this pattern. It is a general question about how
    to get concurrent access to entity beans to work on
    the RI.Entity Beans are the shared components , same instance is being shared between all the concurrent users so if the same component is a part of the longer transaction then the component can lead to the data corruption and to avoid that you have to set the ISOLATION Level for the concurrent running long transactions.Remember the Entity beans are shared components and are shared between all the cliens not like the Sessoin BEans where different clients can get different instances.
    I tried to alter the cloudscape setting to SERIAZABLE,
    but that won't help. (from the cloudscape log, it
    seems, that the container switches back to READ_COMMIT
    before every transaction.You dont have to change the setting in the Cloudscape,you require add the Isolation-level tag in the deployment descriptor.These can take the values as
    1)READ_COMMITED
    2)READ_UNCOMMITTED
    3)REPEATABLE_READ
    4)SERIALIZABLEI hope this will help.
    Regards
    Vicky

  • ORB JNDI and Initializing Bean Access problem

    Hello,
    I am using JBuilder 7 with Mobileset 3 and Borland Enterprise Server 5.0.2.
    I am trying to run one of the sample applications that came with mobileset, I am doing the following:
    I am firstly starting the Server Side application:
    1. Start the Enterprise Server Management Agent (this starts the OSAgent on 14000)
    2. Run the BookStoreServer (this initialises the BookStoreServlet container, starts the web server and partition server)
    If at this point I continue to follow the instructions for the sample and start the client, the client throws an EOFException when it first tries to read a stream that the server is supposed to have sent back.
    Because this happens I started to look at the code on the server in detail and realised that there was a BookSearchClient which acts as a bridge for the BookStoreServlet and BookSearch session bean but this wasn't started (Which I think explains why the clients throws the EOFException).
    When I try and start the BookSearchClient in the server application I was first getting org.omg.CORBA.OBJECT_NOT_EXIST but now (and I don't know why) I am receiving the following:
    -- Initializing bean access.
    javax.naming.NameNotFoundException. Root exception is org.omg.CosNaming.NamingContextPackage.NotFound: IDL:omg.org/CosNaming/NamingContext/NotFound:1.0
    at org.omg.CosNaming.NamingContextPackage.NotFoundHelper.read(NotFoundHelper.java:72)
    at org.omg.CosNaming._NamingContextExtStub.resolve(_NamingContextExtStub.java:406)
    at com.sun.jndi.cosnaming.CNCtx.callResolve(CNCtx.java:440)
    at com.sun.jndi.cosnaming.CNCtx.lookup(CNCtx.java:492)
    at com.sun.jndi.cosnaming.CNCtx.lookup(CNCtx.java:470)
    at javax.naming.InitialContext.lookup(InitialContext.java:347)
    -- Failed initializing bean access.
    at javax.naming.InitialContext.lookup(InitialContext.java:347)
    at com.borland.samples.micro.mobilebookstore.bookstore.javaclient.BookSearchClient.<init>(BookSearchClient.java:53)
    at com.borland.samples.micro.mobilebookstore.bookstore.javaclient.BookSearchClient.main(BookSearchClient.java:172)
    I have been stuck on this for days now and am really stuck, if anyone can help that'll be excellent.
    Regards and Thanks
    John

    hi John,
    I have been stuck on this problem for 2 weeks. My servlet is tryng to lookup the home class to the session bean and crashes at runtime.
    =com.sun.jndi.cosnaming.CNCtx@d35f5f--
    What ejb-jar*.xml (if any) did you set to allow the JNDI lookup of the session bean?
    I am very keen to know!
    many thanks in advance
    Steve Gauci
    ---- code
    JNDIName = "java:comp/env/ejb/SimpleRoster";
    objref = initContext.lookup(JNDIName);
    System.out.println("after lookup of " + JNDIName);
    if (objref == null) {
    System.out.println("JNDI:" + JNDIName + ": objref=" + objref);
    System.out.println("objref found for :" + JNDIName + ": objref=" + objref);

  • Time Capsule - can no longer access on MBP Leopard

    For the past 6 or 7 weeks I can no longer access my Time Capsule from my MBP Leopard. However, I do not beleive this is a Time Capsule issue as I am still accessing (and backing up) successfully from a MBP running Snow Leopard. Note, the access and backup were running fine for over a year and suddenly just stopped working. I've done the basics like repair permissions, software update, checked everything. For soem reason, when I try to access, I can see the Time Capsule, I can connect until I get to Data then "mylaptop Sparse Bundle". When I choose that disk image backup - just continues for ever and ever with a dialog box that says "trying to connect" or something like that.
    Any ideas appreciated ...
    thanks

    lumiere wrote:
    "the current volume could not be mounted". Also "The Current Time Machine backup disk can;t be found".
    Has this Mac had any problems since the last successful backup? Such as hardware repairs, especially a new logic board? A full restore?
    Is the +sparse bundle+ currently mounted? If so, eject it and try again.
    If not, or if that doesn't help, try a "full reset" of Time Machine, per #A4 of Troubleshooting.
    Interesting to note that the final backup (7 weeks ago) failed - it looked like hourly backups worked and the final one failed ("says in progress" ?)
    Yes, that's the partial, failed backup. Since it's incomplete, it won't appear in the "Star Wars" display, etc. Once Time Machine gets started, it will "recover" it, and convert it into a normal backup, with a new date & Time.
    After that long without a backup, Time Machine will have a lot of work to do (including recovering the partial backup), so connect via Ethernet if at all possible. It will still take a while, but be 2-3 times faster than WIFI.

  • Can not login access manager

    mail server version is JES messaging Server 6 2005Q4 :
    My Access Manager:http://hostname:8080/amserver
    last week, i login access manager, under the web label or configuration label�F
    in "ldap" item�Ci add new dc=xx,dc=xx,dc=xx�C
    then save configuration.
    but after that i can not login access manager.
    when i user admin login,it print:"
    Authentication failed".
    what should i do to restore access manage?
    thanks!

    javatoall wrote:
    Hi,
    I login Access Manager, access sample "realm" -> Authentication->
    Advance Properties -> User profiles and then I choiced "Dynamic with user Alias".
    Then I only configure JDBC authentication with mysql database that I don't used ldapservice.
    When I created a one new user in MySQL, I can login into web application that i security as "sample.war" successfull but new user don't right access resource that i protected before.
    When i login access manager with amdmin user, I can not find user that i has been created it in MySQL database. t
    When the users are created through the dynamic profile, the default cn/sn are set to "default" , after creation you need to login to amconsole as amadmin and change/add proper values for these attributes.
    Alternatively you can set the protected resource's policy subject to Authenticated users. This will work but not sure will meet your requirement
    >
    When i login access manager console with new user, it login successful, and view Profile of new user that I has been created.
    Can you tell me How to manage new user that I has been new in MySQL by Access manager console ?
    I want to configure access proteced resourse for that user. How to configure that ?
    read above use the authenticated users subject
    Thank for every help.
    VinhND.

  • How to set up my elderly parent with Mac so that I can use remote access to help her?

    I want to set my elderly mother up with a new Mac mini so that I can use remote access to show her how use email, browse the internet, share photos.  (She lives in KY, I live in OR)
    She has had an iPhone and an iPad for about 6 months and she can barely use them without becoming frustrated.   I want to be able to see her screen with her and show her how to do things.
    My plan is to set her up with a Mac mini and I'll use my MacBookAir to remote into her system.  I'm buying the mini to configure and then I'll mail it to her.
    My question is whether to try to use Back to My Mac or Teamviewer for remote access
    I have broadband with comcast and she has broadband with Access Cable.  Each have their company modem/routers--neither of us have Airport Express.
    I have my own iCloud account and she has her own.   If I use Back to My Mac, it seems that I would need to set up a separate account on my Mac that would sync to her iCloud account.
    Teamviewer seems easier because I don't have to use a separate account.   Any advice?   Anything that I'm not thinking about?

    As Linc says, you can establish a Screen Sharing session via iMessage and Facetime.  The advantage of these 2 approaches is that once your Mom gets used to using them, she will be more comfortable using them to communicate with you.  I've talked to my Mom via iChat (aka iMessage) more since she learned to use them, then in all the years before that (including when I was a child ).  And just being able to see your Mom via Facetime can be useful when you want to gage how she is doing.
    However, if you are any distance from your Mom, they you want backup methods incase something goes wrong.
    So beside iMessage/Facetime, the next best would be Back-to-My-Mac via iCloud, however, you will want to establish her Mac as using your account so that you have the right to take control remotely.
    An alternative that does not mix up your iCloud acounts would be to use TeamViewer.com (which has an unattended mode so you can do off-hour maintenance when your Mom is not around; or check up on her to find out if she is dating - Turns out if I had been paying attention, I would not have been blind-sided by my Mom getting Married again last Summer - she is in her 80's! ).
    LogMeIn.com, as dwb says, can be used the same was as TeamViewer.com
    Both LogMeIn.com and TeamViewer.com are very good at making it easy to get through the home router and if you are having any problems connecting using other Methods, TeamViewer.com or LogMeIn.com will most likely not have any issues.
    Back-to-My-Mac allows screen sharing and file sharing so you can transfer files as well as control the screen.
    Screen Sharing via Messages allows cooperative file transfer. That is to say, you can try pushing a file to your Mom, but she has to accept each transfer.
    TeamViewer.com has an unattended file transfer mode.
    LogMeIn.com requires the paid version to transfer files.  However, there are other ways to transfer files, such as downloading them from the original source on your Mom's system while using screen sharing, using Dropbox (or similar), emailing them, etc...
    Of course if you are really network savvy, you can roll your own via ssh tunnels, port forwarding routers, getting dynamic DNS names, transferring files via scp, or tunneling AFP file sharing, tunneling your screen sharing sessions.  Lots of fun and excitement playing with terminal commands

  • Color Nook can no longer access library . . How can I resolve this problem?

    I have a Color Nook. Recently it was updated automatically. Since the update I can no longer enjoy reading the library books I once could. I used  Overdrive and Adobe Digital Editions to access my county library in the past but can no longer access it.. I get an error message of E_AUTH_BAD_DEVICE_KEY. Apparently I have lost authorization to the AdobeID server.
    How do I resolve this problem?  

    Well, you could start by asking in the Digital Editions forum,
    http://forums.adobe.com/community/adobe_digital_editions
    This is the Reader one.

  • Can I obtain access token from ADFS 3.0 based on OAuth ACS-token that I already have?

    Hello!
    I have the following setup: iOS device, ACS/WAAD is IDP and ADFS 3.0 as RP, securing access to WIF web service.
    I want iOS application users to be able to access ADFS-protected web-service.
    I have created some users in WAAD, configured trust between ACS IDP and ADFS RP.
    ADFS is registered in WAAD with AppID = ADFSAppID
    I am doing the following request in order to obtain authorization token for iOS app user from ACS:
    const string issuerName = "[email protected]";
    const string issuerPassword = "Password!23";
    var authContext = new AuthenticationContext("https://login.windows.net/ADFSAppID");
    var uc = new UserCredential(issuerName, issuerPassword);
    var result = authContext.AcquireToken("http://adfs.appdomain.com/adfs/services/trust",
    "ADFSAppID",
    uc);
    _authHeader = result.CreateAuthorizationHeader();
    So, I have a token from ACS in JWT format.
    Now I need to present this token to ADFS in order to obtain a new token that I can use to access the web-service. I am trying the following POST-query:
    https://adfs.appdomain.com/adfs/oauth2/token?grant_type=authorization_code&code={0}&client_id=ADFSAppID&redirect_uri=http://web_service_url
    However, when I try accessing web service with that token, I am getting 403:unauthorized and redirected back to ADFS.
    I have already tries lots of code solutions, such as
    http://leastprivilege.com/2010/10/28/wif-adfs-2-and-wcfpart-6-chaining-multiple-token-services/
    http://www.cloudidentity.com/blog/2013/07/30/securing-a-web-api-with-windows-server-2012-r2-adfs-and-katana/
    http://blog.scottlogic.com/2015/03/09/OAUTH2-Authentication-with-ADFS-3.0.html
    But somehow the problem remains: I cannot get such authentication token from ADFS that it is accepted by my webservice as a valid token.
    Can anybody provide any links or code samples of token exchange between ACS and ADFS?

    Yes, it is. I was able to authenticate normally, if I am using ADFS as IdP for WIF RP.
    But when Azure is IdP for ADFS-protected WIF WS, I am unable to get tokens that would be accepted by WIF WS

  • My iPhone 5 wont allow me to slide across so i can't gain access

    my iPhone 5 wont slide across so i can't gain access. can you help?

    Hold down the home and power button at the same time until you see the Apple Logo.

  • I have an iTunes account where I have downloaded Digital movies & I am able to see the list on the desktop of the original downloads. When I log on another device with my login I do not see my list to access them. Why can't I access from another device

    I have an iTunes account where I have downloaded Digital movies & I am able to see the list on the desktop of the original downloads. When I log on another device with my login I do not see my list to access them. Why can't I access from another device

    Hey GingCarv,
    Great question. You'll want to download the movies from your purchase history. The following article explains how to do so:
    Downloading past purchases from the App Store, iBookstore, and iTunes Store
    http://support.apple.com/kb/HT2519
    Note: At this time, movies are not available for automatic downloads.
    Thanks,
    Matt M.

Maybe you are looking for

  • Save as Adobe PDF opens the wrong installation of AA

    Hi all, I bought an Adobe CC membership and after a month I found out that my apps were expiring. I accidentally set CC on Dutch (native language) but I ordered the English version. No problem, deinstalled all the apps and reinstalled them in the Eng

  • Original iPhone, how to use it?

    I hooked up my original iPhone and all I can do in iTunes is activate it. I don't need to activate it, I have a new iPhone. I just want to use it as a 4GB iPod touch and maybe some apps. Am I missing something here?

  • I just updated my iphone 5 to ios 7 and updated my itunes...now my iphone is not showing up in itunes devices. Does anyone know how to fix this?

    I just updated my iphone 5 to ios 7 and updated itunes as well...now my iphone is now showing up in itunes devices. Does anyone know how to fix this problem?

  • ASCII Code in ABAP

    Hi Experts, We need to enter a unique ASCII character called 'US' or Unit Separator in a text file being generated through a program. The ASCII code for US is 31. However when we try and do it programmatically the character '#' is getting populated.

  • Photoshop Elements 10 Printing a Photo

    When I open a photo from one of my files in PE10 and want to print it at 4x6 (which I properly indicate in the appropriate box,) it will do that if I keep the photo centered on the page.  But if I move the photo to the top of the page so that I can p