标签:使用jsp显示表格信息
1、jsp保护起来import java.util.ArrayList;
import java.util.List;
public class TableBean {
public List<String> getList() {
List<String> stringList = new ArrayList<String>();
stringList.add("杰克");
stringList.add("马利");
stringList.add("西西");
stringList.add("瘦瘦");
return stringList;
}
}
import java.io.IOException;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import cn.itcast.web.domain.TableBean;
public class TableServlet extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {
//调用模型对象
TableBean tableBean = new TableBean();
List<String> stringList = tableBean.getList();
//绑定到域对象
request.setAttribute("stringList",stringList);
//转发到jsp页面
request.getRequestDispatcher("/WEB-INF/table.jsp").forward(request,response);
}
}
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<body>
<%
//取得域对象中的内容
List<String> stringList = (List<String>)request.getAttribute("stringList");
%>
<table border="1" align="center">
<caption>学员信息</caption>
<tr>
<th>姓名</th>
<td>操作</td>
</tr>
<%
for(String username : stringList){
%>
<tr>
<th><%=username%></th>
<td><a href="#">查看</a></td>
</tr>
<%
}
%>
</table>
</body>
</html>
标签:使用jsp显示表格信息
原文地址:http://blog.51cto.com/357712148/2105063