Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Thread Tools Search this Thread
Old 01-04-2009
Join Date: Feb 2009
Posts: 72
Servlet to call Session beans during runtime


I hope anyone can help me with this.

i'm using a session bean in a servlet. anyone can advise me should i call the bean's create() in the servlet init() or in the doService()?

And can also tell me, whether it is also possible to call the session beans runtime.

Thanks a lot.
Reply With Quote
Old 01-04-2009
Join Date: Dec 2008
Posts: 202
Re: Servlet to call Session beans during runtime

Session Bean interacts with the client and is non persistent in nature. If server crashes all the data stored in Session Bean are lost. But Entity Beans are persistent in nature and in case sever crashes Entity Bean reconstruct its data from the underlying database. Session Beans are used to handle the client request and manage the session and Entity Beans are used to do database processing.

Here you can have the following Example on it.

* MyTestSession.java
package test.session;
import java.lang.*;
import java.rmi.RemoteException;
import javax.ejb.CreateException;
import javax.ejb.EJBException;
import javax.ejb.SessionBean;
import javax.ejb.SessionContext; 

public interface MyTestSession extends javax.ejb.EJBObject{

         public java.lang.String SayHello() throws java.rmi.RemoteException;

Reply With Quote
Old 01-04-2009
Join Date: Mar 2008
Posts: 258
Re: Servlet to call Session beans during runtime

To answer your first question ... if you've ever heard of the MVC (Model-view-controller) pattern or n-tier pattern of development, then the JSP/Servlets are the 'View' part of it - or the 'Presentation' layer in the n-tier system. Meaning, they are primarily responsible just for displaying the data & accepting input. To some extent JSP/Servlets can be 'Controllers', i.e. they can control/define the flow of an application.

However, it is bad design to put your 'Model' part (i.e. the 'business logic' part) in JSP/Servlets. That is what you use the EJBs for.

My advice ? Try to put display logic in JSP/Servlets & put your business logic in EJBs - easy as pie.
Reply With Quote
Old 01-04-2009
Join Date: Jan 2006
Posts: 211
Re: Servlet to call Session beans during runtime

Here i will provide some guidelines, there are many way to access your EJB3 session/entity bean. Also You can use Singlton ServiceLocator(J2EE design pattern) to look up the EJB session bean from the JNDI Naming Server.
So your application flow would be something like this:
JSP (View) -> Servlet (Controller) -> Business Delegate (J2EE Design Pattern) -> Service Locator (J2EE Design Pattern) -> Session Bean (Business Tier)


EJB3 session bean
//session interface
package com.myapp;

import javax.ejb.Stateless;

public interface HelloEJB3 {
public String sayHello();

//session implementation
package com.myapp;

import java.ejb.Stateless;

public class HelloEJB3Bean implements HelloEJB3 {
private String greeting = ?Hello, EJB3!?;

public String sayHello() { return greeting; }
Reply With Quote

  TechArena Community > Software > Software Development
Tags: ,

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Similar Threads for: "Servlet to call Session beans during runtime"
Thread Thread Starter Forum Replies Last Post
Difference between root session and standard user session in gimp Gajagamini Operating Systems 4 17-01-2011 11:14 AM
Windows 7 console session becomes unresponsive after Remote desktop session Krishanu Networking & Security 4 24-12-2010 07:58 AM
What is the Difference between Message Driven Beans and Stateless Session beans Rail racer Software Development 3 12-09-2009 09:48 AM
Using Internet Explorer gives Microsoft Visual C++ Runtime Library Runtime Error Abejar Windows Software 3 22-04-2009 11:02 PM
How to implement Session Beans in Business delegate class? StudyBoy Software Development 3 01-04-2009 09:35 AM

All times are GMT +5.5. The time now is 01:42 AM.