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 Please help me out with this Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Please help me out with this " Watch "Please help me out with this " New topic
Author

Please help me out with this

nash avin
Ranch Hand

Joined: Nov 13, 2003
Posts: 96
Hi,
Will let you know what I have done so far.
E:/sampleapp/WEB-INF/sourcefiles/controller/ControllerServlet1.java
/model/UserValidator1.java
I have set the classpath appropriately
ie., e:/sampleapp/WEB-INF/sourcefiles/controller
/model
This is where the class files will be stored.
I have included in the respective files
package sourcefiles.controller; in ControllerServlet1.java &
package sourcefiles.model; in UserValidator1.java
then in ControllerServlet1.java i have imported
import sourcefiles.model;
This is what I have done
I get a whole bunch of errors for this.The errors are

ControllerServlet1.java:8: package sourcefiles.model does not exist
import sourcefiles.model.*;
^
ControllerServlet1.java:19: cannot resolve symbol
symbol : variable UserValidator1
location: class sourcefiles.controller.ControllerServlet1
UserValidator1.initDatabase();
^
ControllerServlet1.java:38: cannot resolve symbol
symbol : class UserValidator1
location: class sourcefiles.controller.ControllerServlet1
UserValidator1 uv = null;
^
ControllerServlet1.java:51: cannot resolve symbol
symbol : class UserValidator1
location: class sourcefiles.controller.ControllerServlet1
uv = new UserValidator1();
^
ControllerServlet1.java:52: isValid is already defined in doPost(javax.servlet.
ttp.HttpServletRequest,javax.servlet.http.HttpServletResponse)
boolean isValid = UserValidator1.validateUser(connection, user, pass);
^
ControllerServlet1.java:52: cannot resolve symbol
symbol : variable UserValidator1
location: class sourcefiles.controller.ControllerServlet1
boolean isValid = UserValidator1.validateUser(connection, user, pass);
^


Kindly let me know what could be the error.
Your help would be appreciated.
Thanks
AS
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17260
    
    6

Nash, are you familiar with Packages, importing, and classpath?
This will give you access to your classes, cannot resolve means that the class that you are trying to use is not seen in the classpath or the import of your code.
I would also like to point out one thing that I noticed from your original thread here.
It states that you have one class that has the main method, and it is this class that you want your Servlet to call a method on. Now, this statement alone makes me say the design of your classes are, um, politically correct, way off. If a class is the main application class then it should be the starting class, and not a class that some other class should really be calling methods on.
Now if these methods that you want to call initiate a database connection that both this main class and your servlet class needs to use, then I would say that this database intialization method should be in a class of its own, and not where you have it.
Example:
Class A has static void main()
Class B has Database initialization code
Class C is your Servlet.
Now C and A can both have their own instances of B, or B could just be a bunch of static methods, so you don't need an actual instance at all.
Now lets say. Class A is coded basically like this

now Class B is coded like this

Now for the servlet

That is the general idea.
Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17260
    
    6

OK here is a simpel solution for you.

I have included in the respective files
package sourcefiles.controller; in ControllerServlet1.java &
package sourcefiles.model; in UserValidator1.java
then in ControllerServlet1.java i have imported
import sourcefiles.model;


you have "import sourcefiles.model;" well where is the class that you are importing. which means either write
import sourcefiles.model.*;
or
import sourcefiles.model.UserValidator1;
Mark
nash avin
Ranch Hand

Joined: Nov 13, 2003
Posts: 96
Hi,
Thanks for the reply.Will find out.Ignorance can make one sweat.Will keep posting.
Thanks
AS
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Please help me out with this