• 在jsp中接收并处理servlet传过来的含有bean的List


    在jsp中接收并处理servlet传过来的含有bean的List

    例如有以下bean

    package com.test.domain;
    class Student{
    	private Stirng name;
    	private int age;
    	
    	public Student(String name, int age){
    		this.name = name;
    		this.age = age;
    	}
    
    	public String getName(){
    		return this.name;
    	}
    
    	public void setName(Stirng name){
    		this.name = name;
    	}
    
    	public int getAge(){
    		return this.age;
    	}
    
    	public void setAge(int age){
    		this.age = age;
    	}
    }  
    

    在Servlet中有如下代码:

    List<Student> stuList = new ArrayList<Student>();
    stuList.add(new Student("Tom", 19));
    stuList.add(new Student("Jerry", 20));
    request.setAttribute("stuList", stuList);
    

    在jsp中接收并处理传过来的stuList:

    首先在jsp中导入Student的包如下:

    <%@ page import= "com.test.domain.Student"%>    
    

    在JavaScript中通过如下方式处理:

    <script type="text/javascript">
    	var stuName = new Array();
    	<% int i=0;List<Student> stuList = (List<Student>) request.getAttribute("stuList");
    	   for(i = 0; i < stuList.size(); i ++) { %>
    			stuName[<%=i%>] = <%=((Student) stuList.get(i)).getName()%>;				
    	<% } %>
    </script>
  • 相关阅读:
    EMC研究院电面记
    被百度放了鸽子
    最长严格递增子序列算法
    括号配对问题
    RTP 协议
    C++ 纯虚函数, 记上一笔!
    一年又一年
    direct3d Colorkey 应用.
    CEGUI 中文输入与显示
    被遗忘的C,记录一笔
  • 原文地址:https://www.cnblogs.com/liming1593/p/6516533.html
Copyright © 2020-2023  润新知