SSH------jsp将数据传递给action
1.采用的是action的属性传递
传递过来的参数名是action属性名(必须要求名字一致)
比如传递过来的数据:
http://localhost/Struts2_1/login?username=123&userpwd=123
参数名是username和userpwd,那么创建的action类中就有username和userpwd这两个属性
login.jsp;
index.jsp
ppppppp
struts.xml
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd">
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:
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】
推荐阅读
- Docker应用:容器间通信与Mariadb数据库主从复制
- 即将到手三百万
- 画解算法(1.|画解算法:1. 两数之和)
- 思友人
- 一起来学习C语言的字符串转换函数
- C语言字符函数中的isalnum()和iscntrl()你都知道吗
- C语言浮点函数中的modf和fmod详解
- C语言中的时间函数clock()和time()你都了解吗
- 2021/1/15|2021/1/15 数幸福
- 数组常用方法一