SSH------jsp将数据传递给action

1.采用的是action的属性传递
传递过来的参数名是action属性名(必须要求名字一致)
比如传递过来的数据:
http://localhost/Struts2_1/login?username=123&userpwd=123
参数名是username和userpwd,那么创建的action类中就有username和userpwd这两个属性

login.jsp;





Insert title here - 锐客网





















index.jsp





Insert title here - 锐客网


ppppppp






struts.xml

"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd">









/index.jsp
/login.jsp





LoginAction:
package com.wxf.wwsy.action;


import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionSupport;


public class LoginAction extends ActionSupport{


private String username;
private String userpwd;


public String getUsername() {
return username;
}




public void setUsername(String username) {
this.username = username;
}




public String getUserpwd() {
return userpwd;
}




public void setUserpwd(String userpwd) {
this.userpwd = userpwd;
}




@Override
public String execute() throws Exception {
// TODO Auto-generated method stub
System.out.println("用户名:"+this.username+",,密码:"+this.userpwd);
if( this.username.equals("123") && this.userpwd.equals("123")){
return "success";
}else{
return "false";
}
/*return "success"; */
}


}

2.采用的是试题属性传
创建一个实体类ManagerUser:
在action类中创建实体类属性:
ManagerUser:
package com.wxf.wwsy.model;


public class ManagerUser {


private Long userId;
private String username;
private String userpwd;
private Integer roleid;
public String getUsername() {
return username;
}

public Long getUserId() {
return userId;
}


public void setUserId(Long userId) {
this.userId = userId;
}


public void setUsername(String username) {
this.username = username;
}
public String getUserpwd() {
return userpwd;
}
public void setUserpwd(String userpwd) {
this.userpwd = userpwd;
}
public Integer getRoleid() {
return roleid;
}
public void setRoleid(Integer roleid) {
this.roleid = roleid;
}

}




login.jsp:





Insert title here - 锐客网





















LoginAction:
package com.wxf.wwsy.action;


import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionSupport;
import com.wxf.wwsy.model.ManagerUser;


public class LoginAction extends ActionSupport{


private ManagerUser managerUser;

public ManagerUser getManagerUser() {
return managerUser;
}


public void setManagerUser(ManagerUser managerUser) {
this.managerUser = managerUser;
}


@Override
public String execute() throws Exception {
// TODO Auto-generated method stub
System.out.println("用户名:"+managerUser.getUsername()+",,密码:"+managerUser.getUserpwd());
if( managerUser.getUsername().equals("123") && managerUser.getUserpwd().equals("123")){
return "success";
}else{
return "false";
}
/*return "success"; */
}


}


struts.xml:

"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd">







【SSH------jsp将数据传递给action】

/index.jsp
/login.jsp












    推荐阅读