前台页面
<form action="" method="post" id="loginForm">
<table>
<tr>
<td>用户名</td>
<td><input class="td2" type="text" name="username" id="username" ></td>
</tr>
<tr>
<td >密 码</td>
<td><input type="password" name="password" id="password" ></td>
</tr>
</table>
<input type="button" value="登录" οnclick="loginSubmit()">
</form>
JavaScript中的方法:
方式一:
function loginSubmit(){
$.ajax({
type: "POST",
url: "***/login",
data:{
'username':$('#username').val(),'password':$('#password').val()
},
success: function(data) {
}
方式二:
function loginSubmit(){
$.ajax({
type: "POST",
url: "***/login",
data:form1= $('#loginForm').serialize(), //将表单中的数据序列化
success: function(data) {
}
java后台接受的代码:
方式一:
@RequestMapping(value="/login")
public String login(String username,String password,String code,HttpServletRequest request) throws Exception {
}
方式二:(User是用户对象,username和password是它的属性)
@RequestMapping(value="/login")
public String login(User user,HttpServletRequest request) throws Exception {
String username=user.getUsername();
Sting password=user.getPassword();
}
方式三:
@RequestMapping(value="/login")
public String login(HttpServletRequest request) throws Exception {
String username=request.getParameter("username");
Sting password=request.getParameter("password");
}