tags:

views:

76

answers:

2

I am creating a j2ee web appp and I have created the following packages

  • com.cms.controller (to hold servlets)
  • com.cms.business (to hold busines logic)
  • com.cms.dao (to hold data access objects)
  • com.cms.beans (to hold beans)

Now i want to write a functionality. So i have written a index.jsp page which has action = /loginConroller.

Now should I do the folling in loginController?

Authentication authentication = new Authentication();
boolean flag = authentication.chekLoginCredentials(username, passwd)

Will Authentication class consist of only one function? Is this approcach correct?

A: 

Yes, that would be fine, but still you can add some more features that you can get in future which is related to the database like 1) Closing the connection 2) getting the connection etc

harigm
thanks , was very helfulll
akshay
welcome always, you can accpet this as your answer!!!!
harigm
+1  A: 

Normally you would like to get the User model from the DAO and check if it is null or not. If it is null, then display error. If it is not null, then put it in session and proceed.

E.g.

String username = request.getParameter("username");
String password = request.getParameter("password");
User user = userDAO.find(username, password);
if (user != null) {
    request.getSession().setAttribute("user", user);
    response.sendRedirect("home");
} else {
    request.setAttribute("error", "Unknown login, please try again.");
    request.getRequestDispatcher("login").forward(request, response);
}

Or something like that. With only a boolean flag you can't really login the user and you would have to query the DB everytime if you want to get/show details about the logged in user during the session.

BalusC
thanks that was very helpfull
akshay