File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Unable to call java class from servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Unable to call java class from servlet" Watch "Unable to call java class from servlet" New topic
Author

Unable to call java class from servlet

santbir singh
Greenhorn

Joined: Aug 25, 2012
Posts: 6
Hello sir i am new to java and using Apache Tomcat 7.0.22

and i am trying to compile two classes (one is servlet and second is java class called by servlet). After completing my coding i tried to compile both classes first i comiled java classes which was successfully compiled and .class file created but when i tried to compile servlet file its gave me error at the line where i created and instantiate object for java class.

I also got this problem before that time but i solved it by seting the classpath in cmd by putting the command:-

set classpath = .; C:\Program Files (x86)\Apache Software Foundation\Apache Tomcat 7.0.22\webapps\loginnapp\WEB-INF\classes\;

in this folder i contained to java files (Function.java(servlet) and (Register.java(class)))

code for previous was working fine ...

but now second time i got this problem again and i again used this trick but fail to solve the problem. i set the classpath as i setted previously:-

set classpath = .; C:\Program Files (x86)\Apache Software Foundation\Apache Tomcat 7.0.22\webapps\LoginApp\WEB-INF\classes\;

in this folder i contained to java files (Controler.java(servlet) and (ConnectDB.java(class)))

but this time my classpath trick is not working some guys saying that we can set the classpath onetime only second class path not accepted and some says we have to set the both classpath old and new (in one time) because when we set one classpath and after that we set second it removes previous one. I can't understand what that mean

but i am searching for fix (all in one) solution that will work for all application... No seperate path for seprate application
why this problem creates an issue in window 7 please help me to find solution .... if anybody fix it permanently.....

here is code for my servlet:-







Milan Sutaria
Ranch Hand

Joined: Jul 10, 2008
Posts: 121
is the webapp name spelled correctly on second occassion? I see "loginnapp" on first classpath and then I see "LoginApp"


SCJP 6 83%
Working on SCWCD/OCPJWCD
santbir singh
Greenhorn

Joined: Aug 25, 2012
Posts: 6
Hello I am sorry i am not understanding what you mean. I think my code was unable to understand and readable. But I am looking now to my code it seems fine. I think you correct it for me .
One other thing you was asking about the application name loginapp and LoginApp.

I want to clear that loginapp is my previous application which was solved by setting the classpath

and LoginApp is second application where i got stuck and the solution of setting classpath is not working.

If you understand please reply

loginapp and LoginApp is two different application not the name same application name

vipul bondugula
Ranch Hand

Joined: Oct 14, 2010
Posts: 218

Hello sir i am new to java and using Apache Tomcat 7.0.22

and i am trying to compile two classes (one is servlet and second is java class called by servlet). After completing my coding i tried to compile both classes first i comiled java classes which was successfully compiled and .class file created but when i tried to compile servlet file its gave me error at the line where i created and instantiate object for java class.


May be you have put your java classes in default package. This will be one of the reasons.

"It is a compile time error to import a type from the unnamed package". Check whether your classes are in packages.

Thanks
Vipul Kumar.


Thanks
Vipul Kumar
vipul bondugula
Ranch Hand

Joined: Oct 14, 2010
Posts: 218
ConnectDB ca=ConnectDB();


The above line does not instantiate class.

You should use

R. Jain
Ranch Hand

Joined: Aug 11, 2012
Posts: 370
    
    1

santbir singh wrote:



Is object really getting created here??
R. Jain
Ranch Hand

Joined: Aug 11, 2012
Posts: 370
    
    1

vipul bondugula wrote:

Well, I didn't saw the last answer...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Unable to call java class from servlet