This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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 Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "Running Session bean under eclipse" Watch "Running Session bean under eclipse" New topic
Author

Running Session bean under eclipse

Amandeep Singh
Ranch Hand

Joined: Jul 17, 2008
Posts: 844
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{
@EJB

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");
resp.setContentType("text/html");
PrintWriter out = resp.getWriter();
out.println("<html>");
out.println("<head>");
out.println("<title>Hello World!</title>");
out.println("<br> This is EJB Servlet <br>");
out.println("</head>");
out.println("<body>");
// out.println("<h1>EJB Hello World!</h1>");
out.println("</body>");
out.println("</html>");



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
e.printStackTrace();
}


}



}
------------------------------------------------------------------------------------------------------

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: 844
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: 9345
    
    2

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: 844
Jothi,


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
Greenhorn

Joined: Oct 28, 2009
Posts: 13
Hi,
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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Running Session bean under eclipse
 
Similar Threads
Servlet HelloWorld problem
Stateful session beans and JNDI-Lookup in Netbeans 6.8/EJB 3.1 does not work
Package not found error on running servlet !
Configuring JNDI for JavaBean in Tomcat 5
How to test my servlet