File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to create statefull session bean in netbeans 6.9.1

 
pavithra raghu
Greenhorn
Posts: 7
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am finding very difficult in creating an example in statefull session bean in netbeans 6.9.1,
please help
 
Hebert Coelho
Ranch Hand
Posts: 754
Eclipse IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Create a class and anotate it with @Statefull

Maybe this will help: http://netbeans.org/kb/trails/java-ee.html

Welcome to JavaRanch
 
pavithra raghu
Greenhorn
Posts: 7
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this was my servlet program


package servlet;

import bean.statefullLocal;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


@WebServlet(name="servletbean", urlPatterns={"/servletbean"})
public class servletbean extends HttpServlet {
statefullLocal statefull = lookupstatefullLocal();


protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
try {

out.println("<html>");
out.println("<head>");
out.println("<title>Servlet servletbean</title>");
out.println("</head>");
out.println("<body>");
out.println("<h1>Servlet servletbean at " + request.getContextPath () + "</h1>");
int zahl = statefull.getIntMemory();
statefull.setIntMemory(zahl + 10);
out.println(statefull.getIntMemory());
out.println("</body>");
out.println("</html>");

} finally {
out.close();
}
}


@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}


@Override
public String getServletInfo() {
return "Short description";
}// </editor-fold>

private statefullLocal lookupstatefullLocal() {
try {
Context c = new InitialContext();
// return (statefullLocal) c.lookup("java:global/statelessbean-war/statelessbean-ejb/statefull!bean.statefullLocal");
return (statefullLocal) c.lookup("java:global/statelessbean-ejb/statefullLocal");
} catch (NamingException ne) {
Logger.getLogger(getClass().getName()).log(Level.SEVERE, "exception caught", ne);
throw new RuntimeException(ne);
}
}

}

[b]my ejb file is
[/b]


package bean;

import javax.ejb.Stateful;


@Stateful
public class statefull implements statefullLocal {
Integer intMemory=0;
public Integer getIntMemory() {
return intMemory;
}

public void setIntMemory(int intMemory) {
this.intMemory = intMemory;
}

// Add business logic below. (Right-click in editor and choose
// "Insert Code > Add Business Method")

}

and I got the error as
type Exception report

message

descriptionThe server encountered an internal error () that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: PWC1392: Error instantiating servlet class servlet.servletbean

root cause

com.sun.enterprise.container.common.spi.util.InjectionException: Error creating managed object for class servlet.servletbean

root cause

java.lang.RuntimeException: javax.naming.NamingException: Lookup failed for 'java:global/statelessbean-ejb/statefullLocal' in SerialContext [Root exception is javax.naming.NameNotFoundException: statelessbean-ejb]

root cause

javax.naming.NamingException: Lookup failed for 'java:global/statelessbean-ejb/statefullLocal' in SerialContext [Root exception is javax.naming.NameNotFoundException: statelessbean-ejb]

root cause

javax.naming.NameNotFoundException: statelessbean-ejb

note The full stack traces of the exception and its root causes are available in the GlassFish v3 lo




i tried with all the possibilities of lookup but its not working please help in getting output
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic