Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Unable to call java class from servlet

 
santbir singh
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 122
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
is the webapp name spelled correctly on second occassion? I see "loginnapp" on first classpath and then I see "LoginApp"
 
santbir singh
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 219
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
vipul bondugula
Ranch Hand
Posts: 219
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ConnectDB ca=ConnectDB();


The above line does not instantiate class.

You should use

 
R. Jain
Ranch Hand
Posts: 375
1
Java Python Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
santbir singh wrote:



Is object really getting created here??
 
R. Jain
Ranch Hand
Posts: 375
1
Java Python Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
vipul bondugula wrote:

Well, I didn't saw the last answer...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic