获取表单数据

表单中的输入域中的名称是什么,那么后台提供的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() 
     */ 
}
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值