Hi all, I have written a separate class (UserPresent.java),in this class I am doing checking for useid and password provided by a html form.I will post the code now.
I wanted to know how this above code can be incorporated into a servlet code 1) The parameters with which this method should be called from the servlets' doPost() method 2) What will be the return type of this method
Hope that my question is well stated.Help would be greatly appreciated Thanks in advance AS
Well, I have a couple of suggetions on how you should proceed. 1) Remove any presentation logic from UserPresent.java i.e. anything that will send text back to the browser. 2. Place UserPresent.java in a package. 3. Create and implement an interface to UserPresent.java such as
The method will return true if valid username/password or false if not. 3. Create a Servlet that will receive(via the html FORM tag using the POST method) the username and password from a jsp web page and pass it to the UserPresent.validateUser(String username, String password) as parameters. At the minimum you will have to import the package that contains the UserPresent.class. This is one suggestion of many. I hope this helps. Craig.
It sounds to me like you are doing this simply because someone told you that it was a good idea. They're right, but unless you understand why such abstraction is a good thing, you are unlikely to get it right. There's more to it than just moving the code into another class. I think you'd be best served to ask whoever told you this to explain the reasoning behind it. In the meantime, search through these forums for topics on abstraction, encapsulation and the MVC Pattern. That should help you start to understand these concepts.