wood burning stoves 2.0
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes Running Session bean under eclipse Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "Running Session bean under eclipse" Watch "Running Session bean under eclipse" New topic

Running Session bean under eclipse

Amandeep Singh
Ranch Hand

Joined: Jul 17, 2008
Posts: 850
i am deploying-

session bean, servlet- under webapplication in glassfish.

My servelet code looks like this-

package ejb3inaction.example;
import java.io.IOException;
import java.io.PrintWriter;

import javax.ejb.EJB;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.servlet.*;
import javax.servlet.http.*;

public class InvokeEJB extends HttpServlet{

private HelloUser helloUser;
public void service(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException{

try {
InitialContext ctx = new InitialContext();
HelloUser helloUser = (HelloUser) ctx.lookup("ejb/SimpleBeanJNDI");
PrintWriter out = resp.getWriter();
out.println("<title>Hello World!</title>");
out.println("<br> This is EJB Servlet <br>");
// out.println("<h1>EJB Hello World!</h1>");

out.println(helloUser.sayHello("Curious George"));
System.out.println("Invoked EJB successfully .. see server console for output");

} catch (NamingException e) {
// TODO Auto-generated catch block



when i access this servlet, i don't get any output dispalyed, like all out.prinltn line's output,

i am able to access this serlvet thru index.html
it dosen't give's any error, the accessed servlet page remains blank.

Can you let me know why it is blank?

SCJP 1.4, SCWCD 5, SCBCD 5, OCPJWSD 5,SCEA-1, Started Assignment Part 2
My blog- http://rkydesigns.blogspot.com
Amandeep Singh
Ranch Hand

Joined: Jul 17, 2008
Posts: 850
Christophere Verre, at least you can reply...

As i told earlier, there is not much excitement in this forum for EJB3.
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 10033

Did you try to see the server console if it prints this line System.out.println("Invoked EJB successfully .. see server console for output"); ??

I guess you might be facing some JNDI naming issues...

SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
Amandeep Singh
Ranch Hand

Joined: Jul 17, 2008
Posts: 850

Your guess is right, i am getting JNDI Naming exception.
Ok i let you know what i have done,

1) I have deployed Session Bean and Servlet, into 1 web-application.

So i think's that's why it's giving JNDI Naming exception.
Because Session Bean's when deployed under web-application are not recognised by GlassFish Server.

The possible solution that i can try is, today evening at home is to-

1) make Servlet deploy under Web-Application in Glassfish.
2) deploy Session bean under EJB modules in Glassfish.

So i think it's possible, that in Glassfish Server, 1 module component can call other module component's, so in my case, Web-application will call EJB module.

Please correct me, if my suggested solution is wrong somewhere.
S Bhanage

Joined: Oct 28, 2009
Posts: 13
I think if you are getting JNDI Naming exception It might be becoz of the following

Here you have DI without specifying its 'name' field
(This will have default jndi lookup name)

Here you have again HelloUser (which means two differnt beans).

I think you can use it as follows:

Hope this is helpful to you.
I agree. Here's the link: http://aspose.com/file-tools
subject: Running Session bean under eclipse
It's not a secret anymore!