I m developing a small application in JSP using tomcat 6.0.35. My JSP file is in "C:\apache-tomcat-6.0.35\webapps\examples" folder and my java file is in "C:\apache-tomcat-6.0.35\webapps\examples\WEB-INF\classes\ems" folder where ems is my package name. But when i m trying to insert data to the database it gives an exception from my java file located in ems package. The exception is "Exception in thread "main" java.lang.NoClassDefFoundError". My jdk is installed in "C:\Program Files\Java\jdk1.5.0_04". I try to find out the solution in goggle where it says it is due to absence of jar file. Which jar file i have to put and where. I have jstl and standard jar file in "C:\apache-tomcat-6.0.35\webapps\examples\WEB-INF\lib" folder. I also try to put these jar file into lib folder of jdk but still does not work. Please help me to overcome this problem.
Joined: Feb 02, 2009
Deo Sharma wrote:But when i m trying to insert data to the database it gives an exception from my java file located in ems package.
Just to be sure: Do you really have .java files in WEB-INF/classes? Then it can't work...you need to compile your files and put the .class files in there.
Otherwise...what exactly are you trying to do, and in which order? Do you call your class from the JSP? Does your class attempt to connect to and write to the database, or do you do that in your JSP? How is the class related to the JSP? Please tell us what you're doing.
Joined: Apr 14, 2012
I have .class file in WEB-INF/classes and i m calling Java file through JSP as
where ems is my package name and insert_details is my java file name.
All the code for connection and insertion process is in my java file. I m calling this java class file from JSP. I have a function called insert() in java file in which i have written the code for insertion which return boolean value. But when i checked with if(insert()) in JSP it returns false. When i tried to check java code then it is giving exception as said in earlier post. I dont know why, my code is correct. Can i pass parameter from JSP to JAVA while calling a function?
Joined: Feb 02, 2009
Deo Sharma wrote:<jsp:useBean id="insert" class="ems.insert_details" scope="application">
This looks correct. I'd really recommend using the standard convention for naming your class however: large first letter, best no underscores. I suggest you use this statement alone in your JSP, without the second one. If you still get the exception, make sure that you can find the file WEB-INF/classes/ems/insert_details.class in your webapp folder.
Deo Sharma wrote:<jsp:setProperty name="insert" property="*"/></jsp:useBean>
This looks very strange, I doubt it is the correct usage of the tag. The <jsp:setProperty> tag probably expects a real property (with a corresponding setter method in your class), and a value for that property. For example, if you had the setter setMyValue(String str) in your class, you could write
The setter could write the value into the database (as side effect). However, I imagine you want to use the page to gather some input, and then submit that data to the class for insertion? If so, why don't you use a normal form, and write a servlet class to accept the data, and call your classes' method from the servlet code?