首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 服务器 > 其他服务器 >

WEB访问EJB3.0 有状态bean 的有关问题

2013-09-11 
WEB访问EJB3.0 有状态bean 的问题写了一个有状态的会话bean 在main函数中访问没有问题,当我放到JSP中访问

WEB访问EJB3.0 有状态bean 的问题
写了一个有状态的会话bean 在main函数中访问没有问题,当我放到JSP中访问就出现问题了
下面是我的相关代码

远程接口

Java code
import javax.ejb.Remote;@Remotepublic interface CountNumber {    public int getnum();}




有状态Bean实现类

Java code
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 ;    }}




如果在main函数中这样直接访问
Java code
        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());



就可以获得两个值,都是 2

但我想要在WEB应用中访问,就出错,这里是我的JSP页面
Java code
<%@ 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>


下面是错误信息
控制台输出的错误信息

Java code
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) 




这里是页面输出的错误信息
Java code
org.apache.jasper.JasperException: An exception occurred processing JSP page /welcome.jsp at line 1512:         Context cx=new InitialContext();13:         CountNumber cn=(CountNumber)session.getAttribute("cn");14:         if(cn==null){15:             cn=(CountNumber)cx.lookup("CountNumberBean/remote");16:             session.setAttribute("cn",cn);17:         }18:  Stacktrace:    org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:504)    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:415)    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:336)    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)    javax.servlet.http.HttpServlet.service(HttpServlet.java:803)    org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)root causejava.lang.ClassCastException: $Proxy222    org.apache.jsp.welcome_jsp._jspService(welcome_jsp.java:73)    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)    javax.servlet.http.HttpServlet.service(HttpServlet.java:803)    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:373)    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:336)    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)    javax.servlet.http.HttpServlet.service(HttpServlet.java:803)    org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)note The full stack trace of the root cause is available in the JBossWeb/2.0.1.GA logs.

   




请帮我诊断诊断,是否是EJB容器的问题呢?
PS:我的开发环境是 JDK1.5+JBOSSIDE for eclipse


[解决办法]
CountNumber cn=(CountNumber)session.getAttribute("cn");
加个断点看看
[解决办法]
你换个开发环境吧,使用MyEclipse6.5 以及 JBOSS5.0 +JDK6.0用 ,这样就应该不会有什么问题了
我的异常网推荐解决方案:An exception occurred processing JSP page,http://www.myexception.cn/j2se/33144.html

热点排行