转载自:http://lib.csdn.net/article/javaee/6776
jsp页面跟通常的html传值一样 通常有两种方式
$(function() {
bindLogin();
});
function bindLogin() {
$("#btnSubmit").bind("click",
function() {
var txtUserName = $("#username3").val();
var txtPwd = $("#password3").val();
if (! (txtUserName && txtPwd)) {
alert("请输入帐号和密码;");
return;
}
$.getJSON("<%=basePath%>getIp/login?username=" + txtUserName + "&password=" + txtPwd,
function(data) {
alert(data);
if (data.aaa == "fail") {
alert("很抱歉,用户名不存在或者密码错误。---请确认密码");
}else {
window.location.href = "<%=basePath%>index.jsp";
sessionValuesTemp = data.userId;
}
});
});
}
用户名:
密 码:
用户名
密码
方式三提交
传值为封装类
例如我们把用户名密码封装成用户 User
User.java
package entity;
public class User {
private String username;
private String password;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
方式一
LoginAction.java中
public class loginAction extends ActionSupport{
private User user;
public User getUser()
{ return user; }
public void setUser(User user)
{ this.user=user; } }
jsp页面中
用户名:
密 码:
方式二
Action类必须实现ModelDriven接口,同样把表单传来的数据封装起来,Action类中必须实例化该对象,并且要重写getModel()方法
public class loginAction extends ActionSupport implements ModelDriven{
private User user =new User();
public User getModel(){
return user;
}
}