You have to separate your concerns. One way of doing this is to structure your project as follows:
1. Platform
2. Application
Platform contains things like:
1. Domain
2. Services
3. Data Access
4. Utilities.
...
Application contains stuff like (for a web application):
1. Servlet/JSP/Struts/Spring MVC, etc. code
2. HTML,
JSP, CSS
Application depends on platform. In platform, Domain holds representations of objects you are working with. Stuff like Person, User, Address, etc. For your purposes, you probably want to have a User class with two fields - username and password. Services manipulate domain objects. At a high level you might have a class called UserService, with several methods like "User saveUser(
String username, String password);", "User getUser(String username, String password)", etc. The data access layer provides the service with the way to actually interact with the database (I usually roll it into the service layer so it is not visible to the outside). So, you might have a class like UserDao which would contain methods like "User saveUser(String username, String password);", "User getUser(String username, String password)", etc. In your simple example, the service methods simply call (pass through to) the dao methods.
At the application level, you will have to implement a way to display and process a form to login or register. I'm a Spring MVC guy, don't really use
Struts, but I believe the process is similar. You will have a Controller to process the requests, you will have a command object (a form backing object), which will hold the data supplied by the user in the form, and you will have some way of displaying the actual page (something that will generate the html) - a JSP page perhaps. The controller needs basically two methods, "display" and "process form". The first will just render the form to the user. The second will be invoked after the form is submitted. The command object needs to be bound to the form and returned after form processing, and the frameworks handle it in various ways (Spring MVC makes it an input parameter to the "process" method). If you use a simple
servlet, you can retrieve the form values from the request as parameters.
Once you have the data, you call the UserService, get the user, authenticate, save the user, etc. whatever you need to do.