9 Replies Latest reply on Dec 30, 2002 11:29 PM by cyourth

    where should I put javabean class?

    maofan

      hello everyone!
      I ever put javabean class into /WEB-INF/classes/ or
      put .jar into /WEB-INF/lib/. but jboss can't work.
      then where should I put javabean class?

      Please help

      Thanks
      CN


        • 1. Re: where should I put javabean class?
          joelvogt

          this is the right place to put them. How is jboss not working? How are you using them? Also make sure there are no conflicts on your classpath.

          • 2. Re: where should I put javabean class?
            maofan

            I 'm using JBoss-3.0.4_Tomcat-4.0.6
            I have ever written such simple javabean to test:
            UserBean.java
            public class UserBean{
            private String name;
            private String address;
            private String email;
            public UserBean(){}
            public String getName(){
            return this.name;
            }
            public void setName(String name){
            this.name=name;
            }
            public String getAddress(){
            return this.address;
            }
            public void setAddress(String address){
            this.address=address;
            }
            public String getEmail(){
            return this.email;
            }
            public void setEmail(String email){
            this.email=email;
            }
            }


            I put UserBean.class into "WEB-INF/classes"

            test.jsp
            <jsp:useBean id="user" class="UserBean" >
            <jsp:setProperty name="user" property="name" value="testName" />
            <jsp:setProperty name="user" property="address" value="testAddress" />
            <jsp:setProperty name="user" property="email" value="test@hotmail.com" />
            <jsp:getProperty name="user" property="name" />
            <jsp:getProperty name="user" property="address" />
            <jsp:getProperty name="user" property="email" />
            </jsp:useBean>


            but when I run test.jsp

            HTTP Status 500 - Internal Server Error

            --------------------------------------------------------------------------------

            type Exception report

            message Internal Server Error

            description The server encountered an internal error (Internal Server Error) that prevented it from fulfilling this request.

            exception

            org.apache.jasper.JasperException: Unable to compile class for JSP

            An error occurred at line: 0 in the jsp file: /bean.jsp

            Generated servlet error:
            [javac] Compiling 1 source file

            E:\java\jboss\tomcat-4.1.x\work\MainEngine\localhost\test\bean_jsp.java:41: cannot resolve symbol
            symbol : class UserBean
            location: class org.apache.jsp.bean_jsp
            UserBean user = null;
            ^



            An error occurred at line: 0 in the jsp file: /bean.jsp

            Generated servlet error:
            E:\java\jboss\tomcat-4.1.x\work\MainEngine\localhost\test\bean_jsp.java:43: cannot resolve symbol
            symbol : class UserBean
            location: class org.apache.jsp.bean_jsp
            user = (UserBean) pageContext.getAttribute("user", PageContext.PAGE_SCOPE); ^



            An error occurred at line: 0 in the jsp file: /bean.jsp

            Generated servlet error:
            E:\java\jboss\tomcat-4.1.x\work\MainEngine\localhost\test\bean_jsp.java:46: cannot resolve symbol
            symbol : class UserBean
            location: class org.apache.jsp.bean_jsp
            user = (UserBean) java.beans.Beans.instantiate(this.getClass().getClassLoader(), "UserBean");

            ............................

            • 3. Re: where should I put javabean class?
              maofan

              I 'm using JBoss-3.0.4_Tomcat-4.0.6
              I have ever written such simple javabean to test:
              UserBean.java
              public class UserBean{
              private String name;
              private String address;
              private String email;
              public UserBean(){}
              public String getName(){
              return this.name;
              }
              public void setName(String name){
              this.name=name;
              }
              public String getAddress(){
              return this.address;
              }
              public void setAddress(String address){
              this.address=address;
              }
              public String getEmail(){
              return this.email;
              }
              public void setEmail(String email){
              this.email=email;
              }
              }


              I put UserBean.class into "WEB-INF/classes"

              test.jsp
              <jsp:useBean id="user" class="UserBean" >
              <jsp:setProperty name="user" property="name" value="testName" />
              <jsp:setProperty name="user" property="address" value="testAddress" />
              <jsp:setProperty name="user" property="email" value="test@hotmail.com" />
              <jsp:getProperty name="user" property="name" />
              <jsp:getProperty name="user" property="address" />
              <jsp:getProperty name="user" property="email" />
              </jsp:useBean>


              but when I run test.jsp

              HTTP Status 500 - Internal Server Error

              --------------------------------------------------------------------------------

              type Exception report

              message Internal Server Error

              description The server encountered an internal error (Internal Server Error) that prevented it from fulfilling this request.

              exception

              org.apache.jasper.JasperException: Unable to compile class for JSP

              An error occurred at line: 0 in the jsp file: /bean.jsp

              Generated servlet error:
              [javac] Compiling 1 source file

              E:\java\jboss\tomcat-4.1.x\work\MainEngine\localhost\test\bean_jsp.java:41: cannot resolve symbol
              symbol : class UserBean
              location: class org.apache.jsp.bean_jsp
              UserBean user = null;
              ^



              An error occurred at line: 0 in the jsp file: /bean.jsp

              Generated servlet error:
              E:\java\jboss\tomcat-4.1.x\work\MainEngine\localhost\test\bean_jsp.java:43: cannot resolve symbol
              symbol : class UserBean
              location: class org.apache.jsp.bean_jsp
              user = (UserBean) pageContext.getAttribute("user", PageContext.PAGE_SCOPE); ^



              An error occurred at line: 0 in the jsp file: /bean.jsp

              Generated servlet error:
              E:\java\jboss\tomcat-4.1.x\work\MainEngine\localhost\test\bean_jsp.java:46: cannot resolve symbol
              symbol : class UserBean
              location: class org.apache.jsp.bean_jsp
              user = (UserBean) java.beans.Beans.instantiate(this.getClass().getClassLoader(), "UserBean");

              ............................

              • 4. Re: where should I put javabean class?
                maofan

                I 'm using JBoss-3.0.4_Tomcat-4.0.6
                I have ever written such simple javabean to test:
                UserBean.java
                public class UserBean{
                private String name;
                private String address;
                private String email;
                public UserBean(){}
                public String getName(){
                return this.name;
                }
                public void setName(String name){
                this.name=name;
                }
                public String getAddress(){
                return this.address;
                }
                public void setAddress(String address){
                this.address=address;
                }
                public String getEmail(){
                return this.email;
                }
                public void setEmail(String email){
                this.email=email;
                }
                }


                I put UserBean.class into "WEB-INF/classes"

                test.jsp
                <jsp:useBean id="user" class="UserBean" >
                <jsp:setProperty name="user" property="name" value="testName" />
                <jsp:setProperty name="user" property="address" value="testAddress" />
                <jsp:setProperty name="user" property="email" value="test@hotmail.com" />
                <jsp:getProperty name="user" property="name" />
                <jsp:getProperty name="user" property="address" />
                <jsp:getProperty name="user" property="email" />
                </jsp:useBean>


                but when I run test.jsp

                HTTP Status 500 - Internal Server Error

                --------------------------------------------------------------------------------

                type Exception report

                message Internal Server Error

                description The server encountered an internal error (Internal Server Error) that prevented it from fulfilling this request.

                exception

                org.apache.jasper.JasperException: Unable to compile class for JSP

                An error occurred at line: 0 in the jsp file: /bean.jsp

                Generated servlet error:
                [javac] Compiling 1 source file

                E:\java\jboss\tomcat-4.1.x\work\MainEngine\localhost\test\bean_jsp.java:41: cannot resolve symbol
                symbol : class UserBean
                location: class org.apache.jsp.bean_jsp
                UserBean user = null;
                ^



                An error occurred at line: 0 in the jsp file: /bean.jsp

                Generated servlet error:
                E:\java\jboss\tomcat-4.1.x\work\MainEngine\localhost\test\bean_jsp.java:43: cannot resolve symbol
                symbol : class UserBean
                location: class org.apache.jsp.bean_jsp
                user = (UserBean) pageContext.getAttribute("user", PageContext.PAGE_SCOPE); ^



                An error occurred at line: 0 in the jsp file: /bean.jsp

                Generated servlet error:
                E:\java\jboss\tomcat-4.1.x\work\MainEngine\localhost\test\bean_jsp.java:46: cannot resolve symbol
                symbol : class UserBean
                location: class org.apache.jsp.bean_jsp
                user = (UserBean) java.beans.Beans.instantiate(this.getClass().getClassLoader(), "UserBean");

                ............................

                • 5. Re: where should I put javabean class?
                  partha

                  I am having the same problem. I get the exact same
                  errors as posted in this question. My classpath
                  seems to be correct. I don't have problems with
                  running ejb or servlet examples. Can someone shed
                  some light on this?

                  Thanks.
                  Partha

                  • 6. Re: where should I put javabean class?
                    partha

                    can someone please shed some light on this issue?
                    thanks.
                    partha

                    • 7. Re: where should I put javabean class?
                      lijianghua

                      you should put javabean classes in the WEB-INF/classes not the web-inf/classes!
                      for example:
                      I have a class in the WEB-INF/classes/test/Test.class
                      then in my jsp file,I can use it like this:
                      <jsp:useBean id="test" class="test.Test" scope="request"/>
                      then I think,it's ok!
                      just try it like this!

                      • 8. Re: where should I put javabean class?
                        partha

                        Actually, I have put the javabean class in WEB-INF/classes
                        directory. I still get the same error. For example,
                        when I use the bean in a JSP page as follows:

                        <jsp:useBean id="languageBean" class="LanguageBean" scope="request"/>

                        I get the following error:


                        An error occurred at line: 1 in the jsp file: /beans.jsp

                        Generated servlet error:
                        /usr/java/jboss-3.0.3_tomcat-4.0.5/catalina/work/MainEngine/localhost/jspExamples/beans$jsp.java:56: Class org.apache.jsp.LanguageBean not found.
                        LanguageBean languageBean = null;

                        Please let me know what else can go wrong.

                        Thanks.
                        Partha

                        • 9. Re: where should I put javabean class?
                          cyourth

                          1. put UserBean class file into /WEB-INF/classes directory.

                          2. add 'page import' directive to your JSP file to locate your class file.

                          3. if you still have problems, try adding the following attribute to tomcat41-service.xml:

                          &lt;attribute name="Java2ClassLoadingCompliance"&gt;false&lt;/attribute&gt;

                          - default is true
                          - this allows the class files to be loaded from WAR file first.
                          - Java2ClassLoadingCompliance, enables the standard Java2 parent delegation class loading
                          model rather than the servlet 2.3 load from war first model. This is true by default as
                          loading from wars that include client jars with classes used by EJBs causes class
                          loading conflicts. If you enable the servlet 2.3 class loading model by setting this
                          flag to false, you will need to organize your deployment package to avoid duplicate
                          classes in the deployment.

                          4. example JSP code:

                          &lt;%@ page language="java" %&gt;
                          &lt;%@ page import="UserBean" %&gt;

                          &lt;html&gt;
                          &lt;body&gt;

                          &lt;jsp:useBean id="user" class="UserBean" &gt;
                          &lt;jsp:setProperty name="user" property="name" value="testName" /&gt;
                          &lt;jsp:setProperty name="user" property="address" value="testAddress" /&gt;
                          &lt;jsp:setProperty name="user" property="email" value="test@hotmail.com" /&gt;
                          &lt;jsp:getProperty name="user" property="name" /&gt;&lt;br&gt;
                          &lt;jsp:getProperty name="user" property="address" /&gt;&lt;br&gt;
                          &lt;jsp:getProperty name="user" property="email" /&gt;&lt;br&gt;
                          &lt;/jsp:useBean&gt;

                          &lt;/body&gt;
                          &lt;/html&gt;