2
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>User Login.</title>
</head>
<body>
    <h4>User Login.</h4>
    <form:form method="post" name="loginForm" action="login-check">
        <table>
            <tr>
                <td>User Name:</td>
                <td><form:input path="name" value="${form.name}"/></td>
            </tr>
            <tr>
                <td>Password:</td>
                <td><form:input path="password" value="${form.password}"/></td>
            </tr>
            <tr>
                <td colspan="2" align="right"><input type="submit"
                    value="Submit"></td>
            </tr>
        </table>
        <div style="color: red">${error}</div>
    </form:form>

</body>
</html>

This is my Controller :

@RequestMapping("/login-check")
    public ModelAndView  logincheck(@ModelAttribute Form person) {
        // TODO Auto-generated method stub

        int value=service.checkLogin("name", "password");

        if(value>0)
        {

        return "loginsucess";

        }
        else
        {
            return "failure";
        }
    }

I have Form Bean class in which we have User Id and password and Some more field are there with its getter and setter i want to take Input from jsp page and i have to pass in checkLogin method here we define check Login

public int checkLogin(String userName, String userPassword) {
        // TODO Auto-generated method stub
        String SQL_QUERY = " from Form as o where o.userName=? and o.userPassword=?";

        int rowCount = jdbcTemplate.queryForInt(SQL_QUERY);
        return rowCount;
    }

i am trying to get jsp Input Value but unable to get please suggest me how i ll get sot that i can apply condition for this .

Prabhat Singh
  • 192
  • 20
Research Development
  • 884
  • 1
  • 19
  • 39

2 Answers2

1

You have to use a count query and set the parameter for the prepared statement:

 String sql = "SELECT count(*) FROM Form WHERE username = ? and o.userPassword=?";
int count = jdbcTemplate.queryForInt(sql, new Object[] { userName, userPassword});
Jens
  • 67,715
  • 15
  • 98
  • 113
0

Do below changes in your code

@RequestMapping("/login-form")
public String loginForm(Model model, Form field) {
    model.addAttribute("person", new Form()); // added
    return "login";
}

Added modelAttribute in form. And do not specify value attribute in form:input only path attribute is required in your case.

<form:form method="post" modelAttribute="person" name="loginForm" action="login-check">
    ...
    <td><form:input path="name"/></td>
    ...

Added person in @ModelAttribute.

@RequestMapping("/login-check")
    public ModelAndView  logincheck(@ModelAttribute("person") Form person) {
        ...

Now person object will get populated from jsp. Make sure you use valid database query.

Naman Gala
  • 4,670
  • 1
  • 21
  • 55