日期:2014-05-20 浏览次数:21004 次
import javax.ejb.Remote; @Remote public interface CountNumber { public int getnum(); }
import javax.ejb.Stateful; import com.thr.stateful.CountNumber; public @Stateful class CountNumberBean implements CountNumber { private int k=1; public int getnum() { k++; return k ; } }
Context cx=new InitialContext(); CountNumber cn=(CountNumber)cx.lookup("CountNumberBean/remote"); System.out.println(cn.getnum()); Thread.sleep(2000); CountNumber cn2=(CountNumber)cx.lookup("CountNumberBean/remote"); System.out.println(cn2.getnum());
<%@ page language="java" pageEncoding="ISO-8859-1"%> <%@page import="com.thr.stateful.CountNumber"%> <%@page import="javax.naming.Context"%> <%@page import="javax.naming.InitialContext"%> <html> <head> <title>My JSP</title> </head> <body> <% Context cx=new InitialContext(); CountNumber cn=(CountNumber)session.getAttribute("cn"); if(cn==null){ cn=(CountNumber)cx.lookup("CountNumberBean/remote"); session.setAttribute("cn",cn); } out.print(cn.getnum()); %> </body> </html>
11:18:48,453 ERROR [[jsp]] Servlet.service() for servlet jsp threw exception java.lang.ClassCastException: $Proxy222 at org.apache.jsp.welcome_jsp._jspService(welcome_jsp.java:73) at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) at javax.servlet.http.HttpServlet.service(HttpServlet.java:803) at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:373) at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:336) at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265) at javax.servlet.http.HttpServlet.service(HttpServlet.java:803) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175) at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:179) at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583) at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446) at java.lang.Thread.run(Thread.java:595)