13 Replies Latest reply on Sep 1, 2002 2:41 PM by 807553

    Simple JSP and Bean; error 500

    807553
      I am working with a simple JSP program and bean.
      The objective is to learn beans.
      Here is the JSP file:

      <HTML><HEAD><TITLE>Overriding toString() Method</TITLE></HEAD><BODY>
      <%@ page import="OverridingToString"%>
      <%! OverridingToString ots1 = new OverridingToString();
      OverridingToString ots2 = new OverridingToString("New Message");
      %>
      <UL>
      <LI>ots1 = <%=ots1%>
      <LI>ots2 = <%=ots2%>
      </UL>
      </BODY></HEAD>

      Here is the very simple bean:

      public class OverridingToString{
      String message = "Default Message";
      public OverridingToString(){}
      public OverridingToString(String msg){message = msg;}
      public String toString(){ return message; }
      }


      Here is the error:

      Error: 500
      Location: /myJSPs/Hour8/overridingToString.jsp
      Internal Servlet Error:

      org.apache.jasper.JasperException: Unable to compile D:\tomcat\jakarta-tomcat-3.3.1\work\DEFAULT\myJSPs\Hour8\overridingToString_1.java:6: Class OverridingToString not found in import.
      import OverridingToString;
      ^
      1 error

      at org.apache.tomcat.facade.JasperLiaison.javac(JspInterceptor.java:898)
      at org.apache.tomcat.facade.JasperLiaison.processJspFile(JspInterceptor.java:733)
      at org.apache.tomcat.facade.JspInterceptor.requestMap(JspInterceptor.java:506)
      at org.apache.tomcat.core.ContextManager.processRequest(ContextManager.java:968)
      at org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:875)
      at org.apache.tomcat.core.ContextManager.service(ContextManager.java:833)
      at org.apache.tomcat.modules.server.Http10Interceptor.processConnection(Http10Interceptor.java:176)
      at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:494)
      at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:516)
      at java.lang.Thread.run(Thread.java:484)



      Note I am using the data structure D:\tomcat\jakarta-tomcat-3.3.1\webapps\myJSPs\HourXX
      I am using the Sam learn in 24 hour book and presently on hour8.
      Both files OverridingToString.java and overridingToString.jsp are in the folder Hour8
        • 1. Re: Simple JSP and Bean; error 500
          807553
          You have this question going in a couple forums dont you? I believe that the answer was posted @ javaranch.com. Happy coding...

          - Cardwell
          • 2. Re: Simple JSP and Bean; error 500
            807553
            <HTML><HEAD><TITLE>Overriding toString()
            Method</title></head><BODY>
            <%@ page import="OverridingToString"%>
            <%! OverridingToString ots1 = new
            OverridingToString();
            OverridingToString ots2 = new OverridingToString("New
            Message");
            %>
            <UL>
            <LI>ots1 = <%=ots1%>
            <LI>ots2 = <%=ots2%>
            </ul>
            </body></head>
            Shouldn't you be outputting <%= ots1.toString() %> instead of <%=ots1%> (and for ots2 as well)?


            >
            Here is the very simple bean:

            public class OverridingToString{
            String message = "Default Message";
            Also, you might want to consider making the data element private and setting it appropriately in your default constructor:
            private String message;
            
            public OverridingToString(){ message = "Default Message"; } // default constructor
            That way you maintain the integrity of your class.
            • 3. Re: Simple JSP and Bean; error 500
              807553
              Looks like it can't find your class file.
              If you have packaged it into a jar file you can put into the /WEB-INF/lib folder of your webapp, if it's a standalone class file it goes into /WEB-INF/classes of your webapp.


              I am working with a simple JSP program and bean.
              The objective is to learn beans.
              Here is the JSP file:

              <HTML><HEAD><TITLE>Overriding toString()
              Method</title></head><BODY>
              <%@ page import="OverridingToString"%>
              <%! OverridingToString ots1 = new
              OverridingToString();
              OverridingToString ots2 = new OverridingToString("New
              Message");
              %>
              <UL>
              <LI>ots1 = <%=ots1%>
              <LI>ots2 = <%=ots2%>
              </ul>
              </body></head>

              Here is the very simple bean:

              public class OverridingToString{
              String message = "Default Message";
              public OverridingToString(){}
              public OverridingToString(String msg){message = msg;}
              public String toString(){ return message; }
              }


              Here is the error:

              Error: 500
              Location: /myJSPs/Hour8/overridingToString.jsp
              Internal Servlet Error:

              org.apache.jasper.JasperException: Unable to compile
              D:\tomcat\jakarta-tomcat-3.3.1\work\DEFAULT\myJSPs\Hour
              \overridingToString_1.java:6: Class OverridingToString
              not found in import.
              import OverridingToString;
              ^
              1 error

              at
              org.apache.tomcat.facade.JasperLiaison.javac(JspInterce
              tor.java:898)
              at
              org.apache.tomcat.facade.JasperLiaison.processJspFile(J
              pInterceptor.java:733)
              at
              org.apache.tomcat.facade.JspInterceptor.requestMap(JspI
              terceptor.java:506)
              at
              org.apache.tomcat.core.ContextManager.processRequest(Co
              textManager.java:968)
              at
              org.apache.tomcat.core.ContextManager.internalService(C
              ntextManager.java:875)
              at
              org.apache.tomcat.core.ContextManager.service(ContextMa
              ager.java:833)
              at
              org.apache.tomcat.modules.server.Http10Interceptor.proc
              ssConnection(Http10Interceptor.java:176)
              at
              org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTc
              Endpoint.java:494)
              at
              org.apache.tomcat.util.threads.ThreadPool$ControlRunnab
              e.run(ThreadPool.java:516)
              at java.lang.Thread.run(Thread.java:484)



              Note I am using the data structure
              D:\tomcat\jakarta-tomcat-3.3.1\webapps\myJSPs\HourXX
              I am using the Sam learn in 24 hour book and presently
              on hour8.
              Both files OverridingToString.java and
              overridingToString.jsp are in the folder Hour8
              • 4. Re: Simple JSP and Bean; error 500
                807553
                if it's a standalone class file it goes into /WEB-INF/classes of your webapp.
                I have navigated to the folder D:\tomcat\jakarta-tomcat-3.3.1\webapps\ROOT\WEB-INF\classes

                Prior to me placing any classes in the directory there were two files:
                SnoopServlet.class
                SnoopServlet.java

                Is this normal?

                I have put the class OverridingToString.java at D:\tomcat\jakarta-tomcat-3.3.1\webapps\ROOT\WEB-INF\classes

                I still get the same error message:

                Error: 500
                Location: /myJSPs/Hour8/overridingToString.jsp
                Internal Servlet Error:

                What shall I do?
                org.apache.jasper.JasperException: Unable to compile D:\tomcat\jakarta-tomcat-3.3.1\work\DEFAULT\myJSPs\Hour8\overridingToString_1.java:6: Class OverridingToString not found in import.
                import OverridingToString;


                • 5. Re: Simple JSP and Bean; error 500
                  807553
                  Normally a webapp has its own WEB-INF directories. For tomcat to autodeploy webapps from .war files, you place them in the directory that has been assigned a context, the folder that you pointed out is always there by default. So this means that,
                  a) ROOT is a webapp.
                  b) every webapp has its own WEB-INF for the
                  web-app classes,either a jar or class file(s).
                  Here's a easy way to create your own webapp.
                  Create a blank zip file, say call it demo.zip, rename it with a .war extension. Then move the file to D:\tomcat\jakarta-tomcat-3.3.1\webapps\ . Shutdown tomcat & start it up again. Tomcat should autodeploy the webapp. A directory called demo should appear withn webapps directory.
                  Okay, now create a WEB-INF directory, then in it create the lib and classes directory. Put your classes in the classes directory if you have jars, then put them in the lib directory. Move your jsp(s) into the demo
                  directory. I think your pages should work then.

                  I realise that this isn't the best manner to create war files, but it's the best way I could think of to help you along with your learning. Normaly I'd use Ant for that kind of thing, but that's another story to be told.

                  Some clarification on what you were doing:
                  I have put the class OverridingToString.java at >D:\tomcat\jakarta-tomcat-3.3.1\webapps\ROOT\WEB-INF\classes
                  You need to put a class file, not the source. So you need to javac it first, or whatever you use to compile the file. If you put your class files there then only the jsp pages in the ROOT context can access the class files.

                  Here's the second part of the error, although it's related to the first.
                  Error: 500
                  Location: /myJSPs/Hour8/overridingToString.jsp
                  Internal Servlet Error:
                  org.apache.jasper.JasperException: Unable to compile >D:\tomcat\jakarta-tomcat-3.3.1\work\DEFAULT\myJSPs\Hour8\overridingToString_1.java:6: >Class OverridingToString not found in import.
                  import OverridingToString;
                  It's complaining it can't find the class to work with the jsp , so the generated servlet throws an error, remember, you put the source rather than the class file and you put it into the wrong place.

                  I hope it helps you out. I had a hard time working out Jsp by myself too. Then I decided to read the docs on tomcat,used examples and I got a bit better at this.




                  • 6. Re: Simple JSP and Bean; error 500
                    807553
                    Create a blank zip file, say call it demo.zip, rename it with a .war extension.
                    How? I am using Windows but do have access to Unix.
                    I have started winzip for Windows.
                    winzip/start/creat new zip file/ <return>
                    file name: D:\tomcat\jakarta-tomcat-3.3.1\webapps\demo.zip <return>
                    The next screen of creating a zip file, I have to chose a file name or folder to zip. So created an empty file and called it temp.txt
                    rename it with a .war extension.
                    I have right clicked the demo file (which is of type WinZip) and choose rename from pop up dialog box. Renamed it demo.war, please note at this point the demo is still of type "Winzip file"

                    Am I doing this right????????
                    • 7. Re: Simple JSP and Bean; error 500
                      807553
                      Shutdown tomcat & start it up again. Tomcat should autodeploy the webapp. A directory called demo should appear withn webapps directory.
                      No tomcat does not create a directory called demo in webapps. :(

                      The book I am reading is Sams Teach YourSelf JSP in 24 Hours.
                      I haven't had any major problems so far with syntax and code for JSP. So therefore considered it to be a good book, a rating of say 7 out of 10.
                      The book does not explain anything on directories.
                      I would thus be greatful if any URL/book recommendation links of where to put "Java class" files can be read?
                      Thank you in adavance?

                      • 8. Re: Simple JSP and Bean; error 500
                        807553
                        FYI I do most of my development in W2K and bring the war files over to linux or unix environments.

                        I think you can create a zip archive without contents with winzip. You're probably using the winzip wizard.
                        Just rename the zip file to one with a war extension. war stands for web archive and uses the zip format. So they are in fact zip files. There are other special things about them, but it mainly concerns what's in them and the layout of the contents of the war file.

                        I am unsure whether your version of tomcat will autodeploy the war file, there is a webapp manager included with all versions of tomcat, I suggest you take a look at that (Docs come with tomcat). If you want you can switch to version 4.X of tomcat. That definately autodeploys.

                        Create a blank zip file, say call it demo.zip, rename
                        it with a .war extension.

                        How? I am using Windows but do have access to Unix.
                        I have started winzip for Windows.
                        winzip/start/creat new zip file/ <return>
                        file name:
                        : D:\tomcat\jakarta-tomcat-3.3.1\webapps\demo.zip
                        <return>
                        The next screen of creating a zip file, I have to
                        chose a file name or folder to zip. So created an
                        empty file and called it temp.txt
                        rename it with a .war extension.
                        I have right clicked the demo file (which is of type
                        WinZip) and choose rename from pop up dialog box.
                        Renamed it demo.war, please note at this point the
                        demo is still of type "Winzip file"

                        Am I doing this right????????
                        • 9. Re: Simple JSP and Bean; error 500
                          807553
                          I did address this in my earlier post. Perhaps you could download a example war file to take a look ?
                          Go here: http://jakarta.apache.org/builds/jakarta-taglibs/releases/dbtags/
                          and go here for an overview of the dbtags itself, plus installation instructions.
                          http://jakarta.apache.org/taglibs/doc/dbtags-doc/intro.html
                          I would thus be greatful if any URL/book
                          recommendation links of where to put "Java class"
                          files can be read?
                          Thank you in adavance?
                          • 10. Re: Simple JSP and Bean; error 500
                            807553
                            Go here: http://jakarta.apache.org/builds/jakarta-taglibs/releases/dbtags/
                            I downloade the file: jakarta-taglibs-dbtags-1.0-B1.zip
                            unzipped gave me 4 files:
                            dbtags.jar
                            dbtags.tld
                            dbtags-doc.war
                            dbtags-examples.war

                            What shall I do? Where is the HowTo? or help.doc ?
                            What shall I read?
                            What shall I do?

                            I have been to http://jakarta.apache.org/taglibs/doc/dbtags-doc/index.html

                            Are you sure you have given me the right link?????????
                            Here is an overview of the .html page:

                            Overview:
                            The DBTags custom tag library contains tags which can be used to read from and write to a SQL database

                            I have been successful in starting a database, I do not really want to learn any more on this topic.

                            My question is why does it seem to be so esotric in dividing JSP and class files seperately?

                            I am at the end my tether and really frustrated.
                            As I have tried with every known combinationss of folder combination. Of Webapps, ROOT, WEB-INF, classes etc ...


                            Here is all the information again:

                            My JSP File located at: D:\tomcat\jakarta-tomcat-3.3.1\webapps\myJSPs\jsp\Hour8

                            <HTML><HEAD><TITLE>Overriding toString() Method</TITLE></HEAD><BODY>
                            <%@ page import="OverridingToString"%>
                            <%! OverridingToString ots1 = new OverridingToString();
                            OverridingToString ots2 = new OverridingToString("New Message");
                            %>
                            <UL>
                            <LI>ots1 = <%=ots1%>
                            <LI>ots2 = <%=ots2%>
                            </UL>
                            </BODY></HEAD>

                            The class file is at D:\tomcat\jakarta-tomcat-3.3.1\webapps\myJSPs\WEB-INF\classes\Hour8:

                            package Hour8;
                            public class OverridingToString{
                            String message = "Default Message";
                            public OverridingToString(){}
                            public OverridingToString(String msg){message = msg;}
                            public String toString(){ return message; }
                            }

                            I start the simple web Application:

                            http://localhost:8080/myJSPs/jsp/Hour8/overridingToString.jsp

                            Error: 500
                            Location: /myJSPs/jsp/Hour8/overridingToString.jsp
                            Internal Servlet Error:

                            org.apache.jasper.JasperException: Unable to compile D:\tomcat\jakarta-tomcat-3.3.1\work\DEFAULT\myJSPs\jsp\Hour8\overridingToString_1.java:6: Class OverridingToString not found in import.
                            import OverridingToString;
                            ^
                            1 error

                                 at org.apache.tomcat.facade.JasperLiaison.javac(JspInterceptor.java:898)
                                 at org.apache.tomcat.facade.JasperLiaison.processJspFile(JspInterceptor.java:733)
                                 at org.apache.tomcat.facade.JspInterceptor.requestMap(JspInterceptor.java:506)
                                 at org.apache.tomcat.core.ContextManager.processRequest(ContextManager.java:968)
                                 at org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:875)
                                 at org.apache.tomcat.core.ContextManager.service(ContextManager.java:833)
                                 at org.apache.tomcat.modules.server.Http10Interceptor.processConnection(Http10Interceptor.java:176)
                                 at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:494)
                                 at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:516)
                                 at java.lang.Thread.run(Thread.java:484)


                            Please try to help?
                            Some one must be working on similar stuff with JSP???????@???>????@?< <>

                            • 11. Re: Simple JSP and Bean; error 500
                              807553
                              I am aware that you might not want to learn anymore about doing db, the
                              whole idea was to get you to understand the standard deployment of war files, by using readily available examples. You can check out their layout by examining the war files.
                              I have been successful in starting a database, I do
                              not really want to learn any more on this topic.
                              It isn't esoteric to divide your jsp and classes like that. You put your classes or packages
                              in the WEB-INF/lib or WEB-INF/classes because when the web container starts up, that's the first place it starts looking for the (this webapp) classes associated with this application. Sure you can put it anywhere in your system as long as you have a classpath for it, but it isn't good practice. If you do have multple people working on it you'll be asking for trouble. The classes that you put there will only be available to your app. This deployment concept is actually a standard, please read the tomcat docs on that.

                              If you take a further peek at the dbtags, they do have jsp pages which demonstrate the use of their tags. Now I know the tags aren't important to you, but it is probably a good idea to work your way through their jsp page as a reference on how to write one eg: how to import classes and things like that. You seem to be stuck on that, so that is a good way to get answers. Don't worry about what dbtags does :). BTW, if you unpack the dbtags with winzip, you'll find that they have the layout like this :
                              |
                              |-/WEB-INF/lib/*.jar
                              |-/WEB-INF/classes/
                              |-/WEB-INF/web.xml (servlet,taglib and other definitions)
                              |-/WEB-INF/dbtags.tld
                              |-*.jsp,*.html
                              All classes that the jsp needs, are found in the /WEB-INF/lib/ or classes directory. It's that simple. You can confirm this by looking at a jsp there.
                              Also the way you put your classes seemed to have changed. Last time you were using a .class file with no package, now you seemed to have used one. That's fine, but make sure that:
                              a) If you are using a jar, that inside the jar you are using
                              |-Hour8/[the class file]
                              this layout .
                              b) If you are using a jar, make sure that the classes are
                              placed in :
                              |-WEB-INF/lib/Hour8/*.classes
                              since you didn't jar them up. If they are in a jar file,
                              just dump them in :
                              |-WEB-INF/lib/*.jar
                              So here's how the layout of your webapp should look like:
                              From the root of myJSPs
                              |-WEB-INF/lib/*.jar
                              |-WEB-INF/classes/*.class
                              |-WEB-INF/web.xml (you don't generally need one)
                              |-jsp/*.jsp (yes you can put them here)
                              |-*.jsp,*.html,*.css (you can put them here as well.)
                              Compare this with your current layout and see where you are putting them . If you chuck them into the jsp folder tomcat won't find them.
                              Change your layout to match this, and see if it works. And in your import statement, try this instead:
                              <%@page import="Hour8.*" %>
                              This will import all classes under the package Hour8, if there are any.
                              You can be more explicit, you can specify a class as well.
                              <%@page import = "Hour8.OverridingToString"%>

                              As a last resort you could send me a zip of your entire app, I'd be more than happy to rearrange the app for you to work with. Just post another reply with your email add, I'll get in touch with you.


                              My question is why does it seem to be so esotric in
                              dividing JSP and class files seperately?

                              I am at the end my tether and really frustrated.
                              As I have tried with every known combinationss of
                              folder combination. Of Webapps, ROOT, WEB-INF, classes
                              etc ...


                              Here is all the information again:

                              My JSP File located at:
                              D:\tomcat\jakarta-tomcat-3.3.1\webapps\myJSPs\jsp\Hour8


                              <HTML><HEAD><TITLE>Overriding toString()
                              Method</TITLE></HEAD><BODY>
                              <%@ page import="OverridingToString"%>
                              <%! OverridingToString ots1 = new
                              OverridingToString();
                              OverridingToString ots2 = new
                              new OverridingToString("New Message");
                              %>
                              <UL>
                              <LI>ots1 = <%=ots1%>
                              <LI>ots2 = <%=ots2%>
                              </UL>
                              </BODY></HEAD>

                              The class file is at
                              D:\tomcat\jakarta-tomcat-3.3.1\webapps\myJSPs\WEB-INF\c
                              asses\Hour8:

                              package Hour8;
                              public class OverridingToString{
                              String message = "Default Message";
                              public OverridingToString(){}
                              public OverridingToString(String msg){message =
                              = msg;}
                              public String toString(){ return message; }
                              }

                              I start the simple web Application:

                              http://localhost:8080/myJSPs/jsp/Hour8/overridingToStri
                              g.jsp

                              Error: 500
                              Location: /myJSPs/jsp/Hour8/overridingToString.jsp
                              Internal Servlet Error:

                              org.apache.jasper.JasperException: Unable to compile
                              D:\tomcat\jakarta-tomcat-3.3.1\work\DEFAULT\myJSPs\jsp\
                              our8\overridingToString_1.java:6: Class
                              OverridingToString not found in import.
                              import OverridingToString;
                              ^
                              1 error

                              at
                              org.apache.tomcat.facade.JasperLiaison.javac(JspInterc
                              ptor.java:898)
                              at
                              org.apache.tomcat.facade.JasperLiaison.processJspFile(
                              spInterceptor.java:733)
                              at
                              org.apache.tomcat.facade.JspInterceptor.requestMap(Jsp
                              nterceptor.java:506)
                              at
                              org.apache.tomcat.core.ContextManager.processRequest(C
                              ntextManager.java:968)
                              at
                              org.apache.tomcat.core.ContextManager.internalService(
                              ontextManager.java:875)
                              at
                              org.apache.tomcat.core.ContextManager.service(ContextM
                              nager.java:833)
                              at
                              org.apache.tomcat.modules.server.Http10Interceptor.pro
                              essConnection(Http10Interceptor.java:176)
                              at
                              org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolT
                              pEndpoint.java:494)
                              at
                              org.apache.tomcat.util.threads.ThreadPool$ControlRunna
                              le.run(ThreadPool.java:516)
                                   at java.lang.Thread.run(Thread.java:484)


                              Please try to help?
                              Some one must be working on similar stuff with
                              JSP???????@???>????@?< <>
                              • 12. Re: Simple JSP and Bean; error 500
                                807553
                                To Axel ptwork,

                                Many Thanx, for your patience.
                                Many people may look at this post and deem me credulous, and looking back at the post I would have to agree. I have the programming working now, many benedictions to you.
                                I am aware that you might not want to learn anymore about doing db,
                                Not wholly true, I would like to know much more, but didn't want to get distracted in something I was able to rudimentaryly complete. My last message was no rebuff on you earnest plea to help, but it was rash feeling felt at the time.

                                I think the problem stems from a culminating of programming problems that has been happening. This is not the Java/JSP side (apart from this) but a larger problem on distributed programming environment I am working on, which no matter how much I try, does not seem to work.

                                Sid Northfield
                                • 13. Re: Simple JSP and Bean; error 500
                                  807553
                                  To Axel ptwork,

                                  Many Thanx, for your patience.
                                  Many people may look at this post and deem me
                                  credulous, and looking back at the post I would have
                                  to agree. I have the programming working now, many
                                  benedictions to you.
                                  Great, if I was of some help to you then that means you have learnt something about your jsp problem.


                                  >
                                  I am aware that you might not want to learn anymore
                                  about doing db,

                                  Not wholly true, I would like to know much more, but
                                  didn't want to get distracted in something I was able
                                  to rudimentaryly complete. My last message was no
                                  rebuff on you earnest plea to help, but it was rash
                                  feeling felt at the time.
                                  No, I didn't take it as a rebuff, I just thought that the war file that all taglibs ship as would be a good example on the layout of the webapps. Anyway, since I did point out dbtags to you, it's a big hint as to things which you could use to speed up jsp development :).
                                  Just checkout the taglibs site to see what you could use.


                                  >
                                  I think the problem stems from a culminating of
                                  programming problems that has been happening. This is
                                  not the Java/JSP side (apart from this) but a larger
                                  problem on distributed programming environment I am
                                  working on, which no matter how much I try, does not
                                  seem to work.

                                  Sid Northfield