Logo 
Search:

Java Answers

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds
  Question Asked By: Kenneth Bennett   on Jul 30 In Java Category.

  
Question Answered By: Sean Grant   on Jul 30

let me explain what’s going on:

First I want to note that "<jsp:useBean id="accountManager" type="com.acme.atm.ejb.AccountManager"
scope="session"/>" doesn’t mean “lookup for accountManager in scope session  and if not found then instantiate one” but means “lookup for accountManager in scope session”. This is because “type” is used not “class”. So if you lookup something that doesn’t exist in session an InstantiationException will be thrown.

So what comes to your mind? “This accountManager thing should be create()-ed somewhere and put into the session”. Right? Well, a bit different but the same result. When you want to use atm, you first should login to it; there in login.jsp also a useBean as above exists. Because no accountManager exists yet, an InstantiationException is thrown. If you look at web.xml you see that when this exception  occurs in a page, request is forwarded to errors/errorAccountManager.jsp. So the first time  in login page  you’re actually redirected to this error  page and if you look at it, it’s there that the accountManager is create()-ed and put into session! Then you’re forwarded to index.jsp page, and because you’re not logged in you’re forwarded to login.jsp but this time an accountManager exists in session!

I hope it’s now clear for you how accoutnManager is created. Regarding ejb  vs javabean question, ejb is a javabean, all java  classes are beans, just put a getBlabla() in your class and the blabla attribute is accessible from outside world as an attribute of a javabean.

Share: