on 02-04-2007 6:07 AM
I have two stateful session beans Sender and NewSender.Accessing SenderBean is workning fine but NewSender is not workning although they only difffer in the topics they create(for MDB). Acccesing the NewSender with the following code gives NullPointerException.Please look where does the problem lie?? This code is written in a jsp:
Sender sender = (Sender)session.getAttribute("sender");
NewSender newsender = (NewSender)session.getAttribute("newsender");
String text = "" + request.getParameter("message");
if(request.getParameter("Submit")!= null)
{
if (newsender == null || sender == null) {
try {
Context ctx = new InitialContext();
if(text.equalsIgnoreCase(""))
{
Object ref = ctx.lookup("java:comp/env/NewMessageSender");
NewSenderHome newsenderHome = (NewSenderHome)ref;
newsender = newsenderHome.createSender();
request.getSession(true).setAttribute("newsender", newsender);
newsender.sendMessage(text);
}
else if(!text.equalsIgnoreCase(""))
{
Object ref = ctx.lookup("java:comp/env/MessageSender");
out.println(ref);
SenderHome senderHome = (SenderHome)ref;
sender = senderHome.createExceptionSender();
request.getSession(true).setAttribute("sender", sender);
sender.sendMessage(text);
}
} catch (Exception exc) {
log("Error occurred : "+ exc );
}
}
Hi Shilpa,
Where exactly does the NPE occur? If the first bean can be looked up successfully but the other one fails, probably there's something wrong with the configuration of the <ejb-ref> elements in your web.xml - check it out.
BTW, if you use the [code] macros, you could make your code much more readable.
-Vladimir
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
84 | |
10 | |
9 | |
8 | |
6 | |
6 | |
6 | |
5 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.