struts集合类型封装

1.list类型封装

 

 

 

2.map类型封装

 

 

 

 

 

3.封装单个String,Object,List<String>,List<Object>

页面:

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>

    <form action="${pageContext.request.contextPath }/test.action"
        method="post">
  字符串1:<input type="text" name="str1"> <br />

测试字符串数组:<input type="text" name="strs"> <input type="text" name="strs"> <input type="text" name="strs"> <br />

测试字符串数组1:<input type="text" name="strs1[0]"> <input type="text" name="strs1[1]"> <input type="text" name="strs1[2]"> <br />

测试单个对象:<input type="text" name="user.username"> <input type="text" name="user.password"> <br />

测试对象集合: <input type="text" name="users[0].username"> <input type="text" name="users[0].password"> <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <input type="text" name="users[1].username"> <input type="text" name="users[1].password"><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

<input type="text" name="users[2].username"> <input type="text" name="users[2].password"><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="submit" value="提交"> </form> </body> </html>

 

Test.Action:

import java.util.List;

import com.opensymphony.xwork2.ActionSupport;

public class TestAction extends ActionSupport {
    private List<String> strs;
    private List<String> strs1;
    private List<User> users;
    private String str1;
    private User user;
    

    @Override
    public String execute() throws Exception {
        return super.execute();
    }

    public List<String> getStrs() {
        return strs;
    }

    public void setStrs(List<String> strs) {
        this.strs = strs;
    }

    public List<User> getUsers() {
        return users;
    }

    public void setUsers(List<User> users) {
        this.users = users;
    }

    public String getStr1() {
        return str1;
    }

    public void setStr1(String str1) {
        this.str1 = str1;
    }

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    public List<String> getStrs1() {
        return strs1;
    }

    public void setStrs1(List<String> strs1) {
        this.strs1 = strs1;
    }

}

User.java

public class User {
    private String username;
    private String password;

    public String getUsername() {
        return username;
    }

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

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    @Override
    public String toString() {
        return "User [username=" + username + ", password=" + password + "]";
    }

}

 

 

strs:

 

 

strs1

 

 

 

 

users

 

 

 

str1:

 

 

 

 

posted @ 2017-08-21 20:33  QiaoZhi  阅读(343)  评论(0编辑  收藏  举报