• Post Reply Bookmark Topic Watch Topic
  • New Topic

Error creating an instance of class in JSP  RSS feed

 
Ghazala Islam
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to create an instance of a class in a jsp,the class file is in /web-inf/classes/.. in tomcat.But when i try to run the jsp either it says internal server error or object not found.When i try to run the jsp without class instantiation it displays jsp.I am just creating instance by:

myclass mcl = new myclass(), so what am i missing?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66144
144
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check the JSP FAQ for this very question.
 
Charles Lyons
Author
Ranch Hand
Posts: 836
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The FAQ would certainly seem to cover all points:

http://faq.javaranch.com/view?BeansNotFound

In your particular case (since you using direct instantiation and not the <jsp:useBean /> action):

(1) Does your class reside in any particular package, other than the default one? If so, you need to either qualify your classname here with the full package name, or import the package using the page directive:

<%@ page import="package_name" %>

where package_name is the name of your package.

(2) Make sure your class file resides in /WEB-INF/classes/package_path/ (the path /WEB-INF/classes/ is apparently case-sensitive) where package_path is the package_name with all .s replaced by /s (this is the normal JAR structure for deployment of a class).

(3) Make sure your class actually has a no-argument constructor (either an implicit or explicit one) which can be invoked.


So, if your class was:

com.mydomain.MyClass

then you would deploy this to /WEB-INF/classes/com/mydomain/MyClass.class and use JSP syntax of either:



or:




That should sort it out - if not, please re-post with the exact exception stack trace from the server's log.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!