Communication between two session beans in jsp

Posted on 2008-06-26
Last Modified: 2008-06-26
I'm creating a rather complex webpage here, and keeping all methods in one session bean creates an enormous class.
I therefore wonder if it is possible break this into several session beans.
The problem is communication between the session beans.
Say Im using one session for selecting language, and one session for displaying some content.
The java class for language selection is simple: (See code snippet)

Problem: The answer from Content is always 1.

Any idea why?
Or any neat trick to avoid this?


<jsp:useBean id="lang" class="Language" scope="session" />

public class Language implements Serializable {

   private int language = 1;

   private static Reference ref = null;

   public int getLanguage() { return language;}

   public void setLanguage(int language) { this.language = language; }

   public String languageTest() { return language select =  + this.language; }

   public static synchronized Language getDefault() {

       Language obj;

        if (ref != null) {

            obj = (Language) ref.get();

        } else {

            obj = null;


        if (obj == null) {

            obj = new Language ();

            ref = new WeakReference(obj);


        return obj;



and the java class for content is :


<jsp:useBean id="cont" class=" Content " scope="session" />

public class Content implements Serializable {

   private Language language;

   public Content() { language = Language.getDefault(); }   

   public String contentBlock() {

       if(language.getLanguage() == 1) return Some text;

       if(language.getLanguage() == 2) return Some other text;


   public String languageTest() { return language select =  + this.language. getLanguage(); }


Open in new window

Question by:kristian_gr
  • 2
LVL 92

Expert Comment

ID: 21872621
You could have your session bean encapsulate the various beans u need

public class MySessionBean implements Serializable
   private Language language = new Language();
   private Content content = new Content();



Author Comment

ID: 21872895
hmm. not quite what I was looking for.

Is it possible to something like:
public class MySessionBean extends Language, Content

LVL 92

Accepted Solution

objects earned 500 total points
ID: 21872910
> hmm. not quite what I was looking for.

may be a better way, not really my area

> Is it possible to something like:
> public class MySessionBean extends Language, Content

No you can only extend a single class


Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
HashMap Vs TreeMap 12 55
Systems talking to each other 5 124
compre toata in where clue oracle 4 55
eclipse shortcuts 9 45
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

914 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now