This week's book giveaway is in the Java in General forum.
We're giving away four copies of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 and have ishori Sharan & Adam L Davis on-line!
See this thread for details.
Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Unable to call java class from servlet

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:-







 
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

 
Ranch Hand
Posts: 252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 John
Ranch Hand
Posts: 252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

ConnectDB ca=ConnectDB();



The above line does not instantiate class.

You should use

 
Ranch Hand
Posts: 375
1
Python Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

santbir singh wrote:



Is object really getting created here??
 
R. Jain
Ranch Hand
Posts: 375
1
Python Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

vipul bondugula wrote:


Well, I didn't saw the last answer...
 
WHAT is your favorite color? Blue, no yellow, ahhhhhhh! Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic