aspose file tools*
The moose likes Servlets and the fly likes Help please !!!! regarding calling a class from a servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Help please !!!! regarding calling a class from a servlet" Watch "Help please !!!! regarding calling a class from a servlet" New topic
Author

Help please !!!! regarding calling a class from a servlet

nash avin
Ranch Hand

Joined: Nov 13, 2003
Posts: 96
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
Craig Jackson
Ranch Hand

Joined: Mar 19, 2002
Posts: 405
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.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61224
    
  66

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
nash avin
Ranch Hand

Joined: Nov 13, 2003
Posts: 96
Hello,
Thanks for the detailed response.I will think about it and will get back to posting.
Hoping to get this thing working.
AS
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Help please !!!! regarding calling a class from a servlet