【发布时间】:2015-12-18 01:08:31
【问题描述】:
<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>
这是我的控制器:
@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";
}
}
我有表单Bean class,其中我们有User Id 和password,还有更多field 有它的getter 和setter 我想从jsp 页面获取输入,我有传入checkLogin method 这里我们定义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;
}
【问题讨论】:
-
您是如何加载登录页面的?向我们展示你的控制器。
-
@RequestMapping("/login-form") public String loginForm(Model model, Form field) { return "login"; } 使用此代码
标签: java spring jsp model-view-controller