• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Running Session bean under eclipse

 
Ranch Hand
Posts: 856
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Amandeep Singh
Ranch Hand
Posts: 856
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Christophere Verre, at least you can reply...

As i told earlier, there is not much excitement in this forum for EJB3.
 
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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...
 
Amandeep Singh
Ranch Hand
Posts: 856
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic