Storing InitialContext in Servlet Sessions

Storing InitialContext in Servlet Sessions

Question:
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?

Answer:
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:
Heading photo, Metadata.

What is Metadata?

What is metadata? Well, It’s an odd concept to wrap your head around. Metadata is essentially the secondary layer of data that tracks details about the “regular” data. The regular

XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved

AI is revolutionizing fraud detection

How AI is Revolutionizing Fraud Detection

Artificial intelligence – commonly known as AI – means a form of technology with multiple uses. As a result, it has become extremely valuable to a number of businesses across

AI innovation

Companies Leading AI Innovation in 2023

Artificial intelligence (AI) has been transforming industries and revolutionizing business operations. AI’s potential to enhance efficiency and productivity has become crucial to many businesses. As we move into 2023, several

data fivetran pricing

Fivetran Pricing Explained

One of the biggest trends of the 21st century is the massive surge in analytics. Analytics is the process of utilizing data to drive future decision-making. With so much of