This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Murach's Python Programming and have Michael Urban and Joel Murach on-line!
See this thread for details.
Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to access packageless class from a JSP?  RSS feed

 
Ron Newman
Ranch Hand
Posts: 1056
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm just getting started with JSP, and have quickly run into a problem:
My JSP uses some classes (BudgetDAO and MySQLBudgetDAO) that are not in any package. When I try to run the JSP, I get an error page complaining that the classes could not be found (even though they're sitting right in my WEB-INF/classes directory).
[javac] /usr/local/jakarta-tomcat-4.1.24-LE-jdk14/work/Standalone/localhost/budget/budget_jsp.java:53: cannot resolve symbol
[javac] symbol : class BudgetDAO
[javac] location: class org.apache.jsp.budget_jsp
[javac] BudgetDAO dao = new MySQLBudgetDAO();
[javac] ^
Generated servlet error:
[javac] /usr/local/jakarta-tomcat-4.1.24-LE-jdk14/work/Standalone/localhost/budget/budget_jsp.java:53: cannot resolve symbol
[javac] symbol : class MySQLBudgetDAO
[javac] location: class org.apache.jsp.budget_jsp
[javac] BudgetDAO dao = new MySQLBudgetDAO();
[javac] ^
How can I get Jasper to properly find these classes when it compiles my JSP?
 
Rob Ross
Bartender
Posts: 2205
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Java compilation units (ie, classes) always belong to a package. It's a fundamental concept in the way the java namespace is managed. If you don't include an explicit package declaration, the compiler assigns it to the "default" package.
The only practical use of the default package is simple one-file applications and training programs; otherwise you should always have your class' packages explicitly declared.
In the 1.4 version of the JDK, they tightened up the java language spec on this issue, and as a result, classes from the default package cannot be imported. So you have to put your classes into a non-default package if you want to import them into other classes.
 
Ron Newman
Ranch Hand
Posts: 1056
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But I don't want or need to import my packageless classes; I just want to refer to them.
(I can refer to classes in other packages, such as java.util.List or java.io.IOException, without importing them.)
 
Edelweiss Cierniak
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if you don't package it, I think you should put those classes files under WEB-INF/ instead of WEB-INF/classes
at least that is what I do.
Edel
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!