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

Interaction between 2 classes (servlet and someother)

 
nash avin
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 149
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1510
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
nash avin
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply,
Will rectify it and keep posting.
AS
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic