This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes Servlets and the fly likes Interaction between 2 classes (servlet and someother) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Interaction between 2 classes (servlet and someother) " Watch "Interaction between 2 classes (servlet and someother) " New topic
Author

Interaction between 2 classes (servlet and someother)

nash avin
Ranch Hand

Joined: Nov 13, 2003
Posts: 96
Hi all,
I have 2 java files one is a servlet and the other is an ordinary java file which checks to see whether a username and password exists in the database(UserPresent.java).This file has got the presentation layer which has to be put into the servlet.
The servlet file must call the UserPresent.java file.I am going to make an interface to the UserPresent.java file ,I will call it User.java.This User.java file will have a method by name
public boolean validateUser(String username,String pasword) .
The UserPresent.java file will implement this interface.

My question now is,where will these java files be put ?,hope that my point is conveyed.How do I test UserPresent.java file.Kindly excuse me if there is a much more sophisticated way of expressing this.
Hoping to hear from you all
Thanks
AS
Jeffrey Spaulding
Ranch Hand

Joined: Jan 15, 2004
Posts: 149
Hi,
to test the method write a simple Testclass that instantiates User in it's main and find out if you get true when callig the validation method with
a user/pwd pair that clicks.
If that works, place all of your classes in the WEB-INF/classes of your webapp. You should now be able to test the method in your servlet.
If you pack everything together in a jar file, place this file in WEB-INF/lib instead.
Good luck,
J.
nash avin
Ranch Hand

Joined: Nov 13, 2003
Posts: 96
Thanks for the reply,
I have a question regarding the testing of the program as you have said.
I have made a java program UserPresent.java,that implements User.The code is given below.

This is the error I am getting at compile time.I am new to this kindly let me know.
[BOLD]
UserPresent.java:6: illegal start of type
try
^
UserPresent.java:41: <identifier> expected
^
[/BOLD]

Thanks
AS
Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1506
Your try/catch has to be within a method. Your main is where your program execution starts from. You may want to check out a jave textbook for more details.


Bosun (SCJP, SCWCD)
So much trouble in the world -- Bob Marley
nash avin
Ranch Hand

Joined: Nov 13, 2003
Posts: 96
Thanks for the reply,
Will rectify it and keep posting.
AS
 
 
subject: Interaction between 2 classes (servlet and someother)
 
Similar Threads
Question about the package problem.
Help please !!!! regarding calling a class from a servlet
cleanup on session expiring
Compilation error
Help!!!!! calling an instance of a class