• 联动


    1.引入js

    2.联动动态

    动态联动下拉列表

    查询条件:
    年龄: 满足条件的学生:

     --------------------------------------------------------------

     public class DynamicList extends HttpServlet {
    
    private ArrayList students = new ArrayList();
    
     // 定义Student内部类
    
    public static class Student {
    
    private int id;
    
     private String name;
    
    private int age;
    
     private String gender;
    
    private String date;
    
    public Student(int id, String name, int age, String gender, String date) {
    
     super(); this.id = id; this.name = name; this.age = age; this.gender = gender; this.date = date;
    
    } }
    
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    
     // 设置生成文件的类型和编码格式
    
    response.setContentType("text/xml;charset=UTF-8"); // 设置响应内容格式
    
     response.setHeader("Cache-Control", "no-cache");
    
    PrintWriter out = response.getWriter();
    
    String output = ""; // 处理接收到的参数
    
     int age = 0;
    
     if (request.getParameter("age") != null) { // 如果age属性不为空
    
    age = Integer.parseInt(request.getParameter("age")); // 得到age的值
    
    }
    
    ArrayList studentList = new ArrayList();// 创建student集合对象
    
     if (age == 0) studentList = students; else studentList = getStudents(age);
    
    // 生成响应文档
    
     if (!studentList.isEmpty()) {
    
     output += ""; for (int i = 0; i < studentList.size(); i++) { // 遍历对象集合
    
    Student stu = studentList.get(i); // 取得对象
    
     output += "";
    
    output += "" + stu.id + "";
    
    output += "" + stu.name + "";
    
    output += "";
    
    }
    
    output += "";
    
     }
    
    out.print(output); // 向客户端传递信息
    
    out.close();
    
    }
    
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    
     this.doGet(request, response); } // 初始化数据集合
    
     public void init() throws ServletException {
    
     students.add(new Student(1, "Marlin", 22, "Gril", "2007-8-5"));
    
     students.add(new Student(2, "Tom", 22, "Boy", "2007-8-7"));
    
     students.add(new Student(3, "Jack", 22, "Boy", "2007-8-3"));
    
    students.add(new Student(4, "Mac", 23, "Boy", "2007-8-7"));
    
    students.add(new Student(5, "Mercy", 23, "Girl", "2007-8-9"));
    
    students.add(new Student(6, "Rain", 23, "Boy", "2007-8-10"));
    
     students.add(new Student(7, "Luice", 24, "Girl", "2007-8-10"));
    
    students.add(new Student(8, "Jonse", 24, "Boy", "2007-8-11"));
    
     students.add(new Student(9, "Lily", 24, "Girl", "2007-8-12"));
    
    }
    
     // 选出所有满足条件的学生
    
    public ArrayList getStudents(int age) {
    
    ArrayList result = new ArrayList(); // 创建student对象集合
    
     if (!students.isEmpty()) { // 如果集合对象不为空
    
     for (int i = 0; i < students.size(); i++) { // 遍历对象集合
    
    Student student = students.get(i); // 取得对象
    
     if (student.age == age) {
    
    result.add(student);
    
    } } }
    
    return result;
    
    } }
  • 相关阅读:
    曾经拥有,今生无悔
    WinRAR 4.20 beta2 key!注册文件 注册码
    加谁的QQ,并聊天‘
    自己读c
    字符串和字符数组做函数参数是的区别,
    数组
    *p和++对p的影响和对*p的影响
    字符串赋给指针
    memset函数,还没看2013.12.19
    strtock函数小结。
  • 原文地址:https://www.cnblogs.com/mingforyou/p/2410681.html
Copyright © 2020-2023  润新知