3 Replies Latest reply on May 12, 2008 12:11 PM by Thomas Chang

    Problem by using Tomcat (web) to access JBoss (app)

    Thomas Chang Apprentice

      Hi all,

      I build an application based on "http://trailblazer.demo.jboss.com/EJB3Trail/persistence/index.html", which contains an EJB-project (JAR) and a Web-project (WAR).

      If I deploy both on the JBoss server, it runs wonderful.

      Now I deploy the web-project, i.e. the WAR to Tomcat Server 6.0. As I run it, I got error/Exception as follow:

      Exception
      
      org.apache.jasper.JasperException: An exception occurred processing JSP page /addfund.jsp at line 46
      
      43: <br />
      44:
      45: <%
      46: Collection <Fund> funds = cal.getFunds();
      47:
      48: %>
      49:
      
      
      Stacktrace:
       org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:524)
       org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:435)
       org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
       org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
       javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
      
      
      root cause
      
      java.lang.NullPointerException
       org.apache.jsp.addfund_jsp._jspService(addfund_jsp.java:103)
       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:393)
       org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
       org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
       javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
      
      


      The Fund is an Entity Bean.

      I am not sure if I have to include more libraries (JARs) in the web-project or should I copy them in the /lib of Tomcat?

        • 1. Re: Problem by using Tomcat (web) to access JBoss (app)
          Thomas Chang Apprentice

          The JSP looks as follow:

          ...
          <%@ page
           import="javax.naming.*,java.text.*,java.util.*,com.wei.chen.ejbs.stateless.*,com.wei.chen.ejbs.entity.*"%>
          
          <%!private Calculator cal = null;
           private NumberFormat nf = null;
          
           public void jspInit() {
           try {
           InitialContext ctx = new InitialContext();
           cal = (Calculator) ctx.lookup("EntityCalculator/remote");
           } catch (Exception e) {
           e.printStackTrace();
           }
          
           nf = NumberFormat.getInstance();
           nf.setMaximumFractionDigits(2);
           }%>
          
          <%
           if ("AddFund".equals(request.getParameter("action"))) {
           cal.addFund(request.getParameter("fundname"), Double
           .parseDouble(request.getParameter("fundrate")));
           }
          %>
          
          <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
          <html xmlns="http://www.w3.org/1999/xhtml">
          <head>
          <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
          <title>Insert title here</title>
          </head>
          <body>
          <p>Add a new Fund:<br />
          <form action="addfund.jsp" method="POST">Fund Name : <input
           type="text" name="fundname" value=""> Growth rate : <input
           type="text" name="fundrate" value="0.05"><input type="hidden"
           name="action" value="AddFund"><br />
          <input type="submit" value="Add fund"><INPUT type="button"
           value="Close Window" onClick="window.close()"></form>
          <br />
          
          <%
           Collection <Fund> funds = cal.getFunds();
          
          %>
          ...
          


          I get more info for the exception from the CMD-Console as follow:

          javax.naming.NameNotFoundException: Name EntityCalculator is not bound in this C
          ontext
           at org.apache.naming.NamingContext.lookup(NamingContext.java:770)
           at org.apache.naming.NamingContext.lookup(NamingContext.java:153)
           at org.apache.naming.SelectorContext.lookup(SelectorContext.java:137)
           at javax.naming.InitialContext.lookup(InitialContext.java:351)
           at org.apache.jsp.calculator_jsp.jspInit(calculator_jsp.java:21)
           at org.apache.jasper.runtime.HttpJspBase.init(HttpJspBase.java:51)
           at org.apache.jasper.servlet.JspServletWrapper.getServlet(JspServletWrap
          per.java:159)
           at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper
          .java:329)
           at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:3
          20)
           at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
           at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
           at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
          icationFilterChain.java:290)
           at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
          ilterChain.java:206)
           at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV
          alve.java:233)
           at org.apache.catalina.core.StandardContextValve.invoke(StandardContextV
          alve.java:175)
           at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.j
          ava:128)
           at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.j
          ava:102)
           at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineVal
          ve.java:109)
           at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.jav
          a:263)
           at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java
          :844)
           at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.proce
          ss(Http11Protocol.java:584)
           at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:44
          7)
           at java.lang.Thread.run(Thread.java:595)
          ...
          


          That means the stateless session bean "EntityCalculator.java" is not bound successfully from Tomcat to JBoss.

          Somebody has experience?

          • 2. Re: Problem by using Tomcat (web) to access JBoss (app)
            jaikiran pai Master

             

            InitialContext ctx = new InitialContext();


            You will have to change this to pass the context information. That will help Tomcat know that you are looking for an object which resides on JBoss.

            Properties props = new Properties();
            props.put(Context.INITIAL_CONTEXT_FACTORY,"org.jnp.interfaces.NamingContextFactory");
            props.put(Context.PROVIDER_URL,"jnp://localhost:1099");
            
            Context ctx = new InitialContext(props);


            Also, make sure that you add the jbossall-client.jar file (present in %JBOSS_HOME%/client folder) to the lib folder of your WAR in Tomcat.