表单中的输入域中的名称是什么,那么后台提供的get set方法要与之对应:比如
表单中为name = “user”
那么后台必须提供user的get set方法:getUser() setUser()
示例:
表单:
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>My JSP 'list.jsp' starting page</title>
<script type="text/javascript">
function del() {
if (confirm("Are you sure?")) {
return true;
}
return false;
}
</script>
</head>
<body>
<h1>
<font color="red">Users List</font>
</h1>
<s:debug/>
<s:a href="/SSH/index.jsp">返回</s:a>
<table border="1" width="80%" align="center">
<tr>
<th>序号</th>
<th>姓名</th>
<th>密码</th>
<th>性别</th>
<th>删除</th>
<th>更新</th>
</tr>
<s:iterator value="#request.list" var="user">
<tr>
<td><s:property value="#user.userId" /></td>
<td><s:property value="#user.userName" /></td>
<td><s:property value="#user.password" /></td>
<td><s:property value="#user.gender" /></td>
<td align="center"><s:a
href="deleteUser.action?user.userId=%{#user.userId}"
onclick="return del()">Delete</s:a></td>
<td align="center"><s:a
href="updatePUser.action?user.id=%{#user.id}">Update</s:a></td>
</tr>
</s:iterator>
</table>
</body>
</html>
后台:
/**
* @Package: com.whpu.action
* @author: Young
* @date: 2018年5月4日 下午3:13:03
*/
package com.whpu.action;
import javax.annotation.Resource;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import com.opensymphony.xwork2.ActionSupport;
import com.whpu.bean.User;
import com.whpu.service.UserService2;
/**
* @ClassName: DeleteUserAction
* @Description: TODO
* @author: Young
* @date: 2018年5月4日 下午3:13:03
*/
@Controller
@Scope("prototype")
public class DeleteUserAction extends ActionSupport{
// @Fields serialVersionUID : TODO
private static final long serialVersionUID = -7734210248215754609L;
@Resource(name="userService2")
private UserService2 userService;
private User user = new User();
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
@Override
public String execute() throws Exception {
System.out.println("-------UserAction.deleteUser-----------"+user.getUserId());
userService.delete(user);
return SUCCESS;
}
/* (non Javadoc)
* @Title: getModel
* @Description: TODO
* @return
* @see com.opensymphony.xwork2.ModelDriven#getModel()
*/
}