I am trying to access an EJB from a JSP and have the foll code piece: (i am using weblogic 6.0)
..............
String url = "t3://localhost:7001";
public Context getInitialContext() throws Exception {
Properties p = new Properties();
p.put(Context.INITIAL_CONTEXT_FACTORY,
"weblogic.jndi.WLInitialContextFactory");
//p.put(Context.PROVIDER_URL, url);
return new InitialContext(p);
}
String getStackTraceAsString(Exception e)
{
// Dump the stack trace to a buffered stream, then send it's contents
// to the JSPWriter.
ByteArrayOutputStream ostr = new ByteArrayOutputStream();
e.printStackTrace(new PrintWriter(ostr));
return(ostr.toString());
}
%>
<%
String op="";
try {
// Contact the AccountBean container (the "AccountHome") through JNDI.
Context ctx = getInitialContext();
out.println("initial context got !!");
DemoHome home = (DemoHome) ctx.lookup("demo.DemoHome");
out.println("home got !!");
%>
<%
Demo ac = null;
try {
ac = (Demo) home.create();
out.println("create called!!");
if (ac==null)
out.println("ac is null!");
}
catch (Exception ee) {
out.print("exception 1");
}
%>
<%
try {
out.println("going to call method!");
if (ac!= null)
op = ac.demoSelect();
else
out.println("ac is null->error!!");
out.println(ac.demoSelect());
out.println("string got!!");
out.println(op);
}
catch (Exception e) {
getStackTraceAsString(e);
e.printStackTrace();
out.println("error 2");
}
}
catch(Exception e)
{
out.println("error 3!");
}
..................
It gives an error on trying to access the method "demoSelect".
e.printStackTrace gives the output:
-------------------
java.lang.RuntimeException: javax.ejb.EJBContext.getEnvironment is deprecated in EJB 1.1. EJB 1.1 compli
ant containers are not required to implement this method. Use java:comp/env instead.
<--------------------
What is wrong???
pls help
-R
-
EJBContext error (3 messages)
- Posted by: Rajat Nayer
- Posted on: June 16 2003 08:19 EDT
Threaded Messages (3)
- your ejb is wrong. by han collin on June 16 2003 23:32 EDT
- EJBContext error - lookup() method error by Srinivasa Rao Chintala on June 17 2003 01:36 EDT
- Error Found - in EJB by Rajat Nayer on June 17 2003 07:48 EDT
-
your ejb is wrong.[ Go to top ]
- Posted by: han collin
- Posted on: June 16 2003 23:32 EDT
- in response to Rajat Nayer
Check your code of EJB.
the method getEnvironment() has been Deprecated. -
EJBContext error - lookup() method error[ Go to top ]
- Posted by: Srinivasa Rao Chintala
- Posted on: June 17 2003 01:36 EDT
- in response to Rajat Nayer
Your lookup() code is wrong that is shown above. You are using EJB 1.0 type of lookup. You need to use lookup("java:comp/env/....") which is part of EJB 1.1 spec.
Hope this helps.
Regards,
Chintala -
Error Found - in EJB[ Go to top ]
- Posted by: Rajat Nayer
- Posted on: June 17 2003 07:48 EDT
- in response to Srinivasa Rao Chintala
Yeah .. I found out that the EJB's setSessionContext method was referring to getEnvironment() method which is now deprecated. This was what was giving a problem. I just removed that invocation and the whole thing worked fine.
Please note that I did not make any changes in the JSP at all.
So, I guess, the JSP lookup code is as per EJB 1.1 reqmnts.
Any comments, Chintala?