Question

I am implementing a basic login form in Spring Web MVC Framework. My goal is the following:

  1. Get the username and password from a user
  2. Process it i.e. find out if username and password are matching those from a DB
  3. Return response - login SUCCESSFUL or FAILURE

I successfully obtain all the information from a user with my controller but unfortunately I get stuck at the second point because I don't know exactly how is Spring dealing with such situations.

I imagine in this way: DAO is an interface which is responsible to transfer data from a form on one side and the DB on the otherside. Everything else is MAGIC for me at this point.

Please enlighten me!

-------------------------------------------------------------------------------------

login.jsp


<!-- code -->
<div class="content">
            <table>
                <tr>
                    <td><form:label path="username">Username</form:label></td>
                    <td><form:input path="username" /></td>
                    <td><form:errors path="username" cssClass="error"/></td>
                </tr>
                <tr>
                    <td><form:label path="password">Password</form:label></td>
                    <td><form:input path="password" /></td>
                    <td><form:errors path="password" cssClass="error"/></td>
                </tr>
            </table>                
</div>
<!-- code -->

FormDao.java


package si.src.dataAccess;

import si.src.forms.Obrazec;

public interface FormDao {

    /* DAO methods */
    public void saveForm(Obrazec obrazec);

}

FormDaoImpl.java


package si.src.dataAccess;

import org.springframework.stereotype.Repository;

import si.src.forms.Obrazec;

@Repository
public class FormDaoImpl implements FormDao{

    public void saveForm(Obrazec obrazec) {
        // TODO Auto-generated method stub  
    }

}

==================================================================================

Was it helpful?

Solution

Why don't you use Spring Security, which handles all this for you. It even contains DB authentification.

http://www.mkyong.com/spring-security/spring-security-form-login-using-database/

Don't reinvent the wheel ;-)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top