2 qq 35103398 qq_35103398 于 2017.09.12 16:11 提问

struts2中action与jsp无法进行数据交互

__问题一:action 的数据不能传到jsp
浏览器输入http://localhost:8080/itcastTax/nsfw/user_listUI.action访问listUI.jsp的结果如下:
图片说明

  1. 不能将数据库的user显示出来 2.从Debug可以看到action已经从数据库的数据取到listuser 图片说明

__问题二:jsp的数据不能传到action

  1. 在listUI.jsp点击"新建"进入addUI.jsp,输入数据点击保存,在数据库的user并没有添加。
    2.debug看到UserAaction.add()方法取到的user为空:
    图片说明

    图片说明

关键代码如下:
User.java:
package cn.itcast.nsfw.user.entity;
import java.io.Serializable;
import java.util.Date;
public class User implements Serializable {
private String id ;
private String name;
private String dept ;
private String account ;
private String password ;
private String headImg ;
private boolean gender;
private String email;
private String mobile;
private Date birthday;
private String state;
private String memo;
public static String USER_STATE_VALID = "1";
public static String USER_STATE_INVALID = "0";
public User() {
super();
// TODO Auto-generated constructor stub
}
public User(String id, String name, String dept, String account,
String password, String headImg, boolean gender, String email,
String mobile, Date birthday, String state, String memo) {
super();
this.id = id;
this.name = name;
this.dept = dept;
this.account = account;
this.password = password;
this.headImg = headImg;
this.gender = gender;
this.email = email;
this.mobile = mobile;
this.birthday = birthday;
this.state = state;
this.memo = memo;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDept() {
return dept;
}
public void setDept(String dept) {
this.dept = dept;
}
public String getAccount() {
return account;
}
public void setAccount(String account) {
this.account = account;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getHeadImg() {
return headImg;
}
public void setHeadImg(String headImg) {
this.headImg = headImg;
}
public boolean isGender() {
return gender;
}
public void setGender(boolean gender) {
this.gender = gender;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getMobile() {
return mobile;
}
public void setMobile(String mobile) {
this.mobile = mobile;
}
public Date getBirthday() {
return birthday;
}
public void setBirthday(Date birthday) {
this.birthday = birthday;
}
public String getState() {
return state;
}
public void setState(String state) {
this.state = state;
}
public String getMemo() {
return memo;
}
public void setMemo(String memo) {
this.memo = memo;
}
UserAction.java:
package cn.itcast.nsfw.user.action;
import java.util.List;
import javax.annotation.Resource;
import org.junit.Test;
import cn.itcast.nsfw.user.entity.User;
import cn.itcast.nsfw.user.service.UserService;
import com.opensymphony.xwork2.ActionSupport;
public class UserAction extends ActionSupport {
private static final User User = null;
@Resource
private UserService userService;
private List userList;
private User user;
//列表页面
public String listUI(){
userList = userService.findobjects();
return "listUI";
}
//跳转新增页面
public String addUI(){
return "addUI";
}
//保存新增
public String add(){
if(user !=null){
userService.save(user);
}
return "list";
}
.
.
.
listUI.jsp
图片说明
addUI.jsp
图片说明
strusr.xml
图片说明

2个回答

QingFeng240
QingFeng240   2017.09.12 17:47

道友你好,请问你是哪个校区的,哪一期的啊?

qq_35103398
qq_35103398 广州今年的。我发的这贴有把问题说清楚了吗?你看懂了没?
2 个月之前 回复
qq_35103398
qq_35103398   2017.09.13 14:01

广州今年的。我发的这贴有把问题说清楚了吗?你看懂了没?

Csdn user default icon
上传中...
上传图片
插入图片