Storing InitialContext in Servlet Sessions

Suppose a client of a Web application logs in using a login-handler servlet, and then some back-end operations using EJBs need to be performed. Can I store the initial context that I create and/or the home interface itself?

Yes, you can store both the InitialContext instance and the home interface instance. You will only want to store the InitialContext ifyou plan on creating other EJBs later in the session. Rather than store an InitialContext in an HttpSession, you should save it as a member variable since you can use the same InitialContext to create EJBs for different sessions.

You can store a home interface in the client’s session, but keep in mind that it is better to do this only with session beans. You will typically create one session bean per client session and let the session bean interact with entity beans. You may want to create multiple session beans in the servlet during the life of a session to perform different tasks, such as authentication.

Alternatively, you may want to create a single session bean that encapsulates all of the actions that may occur during a session. This master session bean will create other session beans as needed to perform the desired tasks. Ultimately, one of the important roles a servlet in J2EE is tobind session beans to servlet client sessions.

Share the Post:
Share on facebook
Share on twitter
Share on linkedin


The Latest

microsoft careers

Top Careers at Microsoft

Microsoft has gained its position as one of the top companies in the world, and Microsoft careers are flourishing. This multinational company is efficiently developing popular software and computers with other consumer electronics. It is a dream come true for so many people to acquire a high paid, high-prestige job

your company's audio

4 Areas of Your Company Where Your Audio Really Matters

Your company probably relies on audio more than you realize. Whether you’re creating a spoken text message to a colleague or giving a speech, you want your audio to shine. Otherwise, you could cause avoidable friction points and potentially hurt your brand reputation. For example, let’s say you create a

chrome os developer mode

How to Turn on Chrome OS Developer Mode

Google’s Chrome OS is a popular operating system that is widely used on Chromebooks and other devices. While it is designed to be simple and user-friendly, there are times when users may want to access additional features and functionality. One way to do this is by turning on Chrome OS