Page 1 of 2 12 Last
  • Jump to page:
    #1
  1. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2002
    Posts
    135
    Rep Power
    12

    JSP newbie: My first JavaBean


    Hey guys. This is my first time with JSP, and I'm trying to create a JavaBean. I seem to be getting an error when I try to set up the following:

    I have a folder called "test" which is the root of my app. Under this directory, I have a folder called "WEB-INF", then a folder called "classes" then the folder called "mathy". Under "mathy" I have a the java file called average.java along with the compiled class file.

    The code for average.java is as follows:

    package mathy;
    import java.io.Serializable;

    public class average implements Serializable {

    private double total = 0;
    public average(double n1, double n2, double n3) {
    total = n1 + n2 + n3;
    total = total / 3;
    }
    public double getAverage() {
    return total;
    }
    }

    then under the original "test" folder, I have a jsp page called "exp-1.jsp" with the following code:

    <% mathy.average av1 = new mathy.average(34.4, 56.1, 694.3); %>

    Now, I'm not trying to execute any methods, just trying to see if a bean can be made. But now luck. Can anyone help? Thanks, I really appreciate it.


    I get the following error by the way with Tomcat Version 4.0-b5:


    A Servlet Exception Has Occurred
    org.apache.jasper.JasperException: Unable to compile class for JSPC:\jakarta-tomcat-4.0-b5\work\localhost\test\exp_0002d4_jsp.java:55: Class mathy.average not found.
    mathy.average av1 = new mathy.average(34.4, 56.1, 694.3);
    ^
    C:\jakarta-tomcat-4.0-b5\work\localhost\test\exp_0002d4_jsp.java:55: Class mathy.average not found.
    mathy.average av1 = new mathy.average(34.4, 56.1, 694.3);
    ^
    2 errors
  2. #2
  3. No Profile Picture
    Moderator =(8^(|)
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Feb 2002
    Location
    Sacramento, CA
    Posts
    1,710
    Rep Power
    14
    Stick this at the top of your jsp file. Should be the second line or so, after your language declaration.
    Code:
    <%@ page import="mathy.average" %>
  4. #3
  5. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2002
    Posts
    135
    Rep Power
    12
    Thanks for the reply! However, now I just get one error instead of two. Someone mentioned that I had to include

    import java.beans.*;

    in my original java bean. Is this correct? I response would be greatly appreciated. Thanks again!

    The error:

    A Servlet Exception Has Occurred
    org.apache.jasper.JasperException: Unable to compile class for JSPC:\jakarta-tomcat-4.0-b5\work\localhost\test\exp_0002d6_jsp.java:3: Class mathy.average not found in import.
    import mathy.average;
    ^
    1 error
  6. #4
  7. No Profile Picture
    Moderator =(8^(|)
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Feb 2002
    Location
    Sacramento, CA
    Posts
    1,710
    Rep Power
    14
    You're not using any of those classes, so no.

    Is the first line in average.java "package mathy;" (without the quotes)?
  8. #5
  9. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2002
    Posts
    135
    Rep Power
    12
    Yeap, no quotes. Should there be quotes?
  10. #6
  11. No Profile Picture
    Moderator =(8^(|)
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Feb 2002
    Location
    Sacramento, CA
    Posts
    1,710
    Rep Power
    14
    Try just average, instead of mathy.average, as in
    Code:
    average av1 = new average();
  12. #7
  13. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2002
    Posts
    135
    Rep Power
    12
    Ugh... still nothing. This is frustrating. I don't know what I could be doing wrong. Do I have to maybe edit the paths in the XML files? What could it be?
  14. #8
  15. No Profile Picture
    Moderator =(8^(|)
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Feb 2002
    Location
    Sacramento, CA
    Posts
    1,710
    Rep Power
    14
    Ya, your web-inf/classes folder isn't in the classpath for some reason. As to why...?
  16. #9
  17. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2002
    Posts
    135
    Rep Power
    12
    How do I fix this? Where in the XML file do I change this? Thanks for your help so far, and patience.
  18. #10
  19. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2002
    Posts
    135
    Rep Power
    12
    Thanks for the help! Problem solved... I had to move the mathy folder and the class within to the WEB-INF... and NOT classes folder. Another option was to include

    package classes.mathy;

    instead of

    package mathy;

    but now it works. Why is this? I thought Tomcat automatically looked for classes in the WEB-INF\classes folder... or so I thought by this book I'm reading.

    Also, everytime I edit a JSP file, and I try to refresh, I don't get an updated version... just the original page that I viewed first. Anyone got a solution? Thanks again.
  20. #11
  21. No Profile Picture
    Moderator =(8^(|)
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Feb 2002
    Location
    Sacramento, CA
    Posts
    1,710
    Rep Power
    14
    Well, MY installation of Tomcat looks in the classes folder
    In your server.xml set your webapp to reload="true" (or something like that. There's a an example with the flag set). When you change the bean, though, you'll have to restart Tomcat to see any changes.
  22. #12
  23. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2002
    Posts
    135
    Rep Power
    12
    Hmm... that's odd. I see a reloadable attribute with I defined my test path. This test path is where I have my JSPs and my WEB-INF folder.

    <Context path="/test" docBase="test" reloadable="true" debug="0"/>

    I already have it as true. I tried deleting the work directory under the %tomcatHome% directory, and that seems to work until I view the page, and tomcat creates this work directory again. So when I try to refresh the page, because the work folder is still there, the page does not get refreshed. Weird... any solutions? Thanks.
  24. #13
  25. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2002
    Posts
    135
    Rep Power
    12
    Someone one mentioned that I had to delete the work directory under the %tomcatHome% directory and restart tomcat. I still have no luck with the refresh however. No matter how many times I try to delete the work directory, restart tomcat - nothing. I have to delete the work direectory manually everytime I want to refresh the JSP for an update that I did. Any solutions? Thanks.
  26. #14
  27. No Profile Picture
    Moderator =(8^(|)
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Feb 2002
    Location
    Sacramento, CA
    Posts
    1,710
    Rep Power
    14
    You've got a seriously messed up Tomcat install Are you in a situation where you can grab the latest Tomcat version and reinstall? I'm not sure, but that might end up clearing up a lot of the issues you're having.
  28. #15
  29. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2002
    Posts
    135
    Rep Power
    12
    I'm currently using Version 4.0-b5... and I'm seriously considering updating. The reason why I was sticking with it is because I'm using a Wrox Books for learning JSP... but the more I read, the more fed up I get - nothing works.

    Do you or anyone else know a good place to get installations/setup instructions for the Tomcat 4.1.x? I would really appreciate it, as I think I'm going to bonkers trying to work with 4.0-b5. Thanks.
Page 1 of 2 12 Last
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo