我在action里得到一个list,list里面是数组,如何把这个数组里的值显示在页面

2024-12-01 11:03:25
推荐回答(3个)
回答1:

首先得通过action传到页面如:
List list = dao.find();
在jsp页面加上这个就可以调用EL表达式
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>

${iwl[1]}

回答2:

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>






My JSP 'test.jsp' starting page












<%
//假设这是List
List list = new ArrayList();
//加入数据
String[] s1= new String[2];
s1[0] = "s1[0]";
s1[1] = "s1[1]";

String[] s2= new String[2];
s2[0] = "s2[0]";
s2[1] = "s2[1]";

list.add(s1);
list.add(s2);

//以上是模拟数据.

for(String[] s:list){
System.out.println("--o-"+s[0]);
System.out.println("--1-"+s[0]);
}
System.out.println("方法二:");
//或者:
for(int i=0;i String[] s = list.get(i);
System.out.println("--o-"+s[0]);
System.out.println("--1-"+s[0]);
}
%>


回答3:

循环显示呗