aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes how to create statefull session bean in netbeans 6.9.1 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "how to create statefull session bean in netbeans 6.9.1" Watch "how to create statefull session bean in netbeans 6.9.1" New topic
Author

how to create statefull session bean in netbeans 6.9.1

pavithra raghu
Greenhorn

Joined: Dec 22, 2011
Posts: 7
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

Joined: Jul 14, 2010
Posts: 754

Create a class and anotate it with @Statefull

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

Welcome to JavaRanch


[uaiHebert.com] [Full WebApplication JSF EJB JPA JAAS with source code to download] One Table Per SubClass [Web/JSF]
pavithra raghu
Greenhorn

Joined: Dec 22, 2011
Posts: 7
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to create statefull session bean in netbeans 6.9.1