使用下面这个jsp的前你需要写一个Stu类生成set和get方法
Public Class Stu{ private int id; private String name; public void setId(int id){ thisid=id; } public int getId(){ return thisid; } public void setName(String name){ thisname=name; } public String getName(){ return thisname; }}
写个简单的servlet
public class gotoMall extends HttpServlet {public void doGet(HttpServletRequest request HttpServletResponse response)throws ServletException IOException {ArrayList<Stu> stus=new ArrayList<Stu>();Stu stu=new Stu();stusetId();stusetName("aa");stusetId();stusetName("bb");stusadd(stu);stusadd(stu);requestsetAttribute("stus" stus);requestgetRequestDispatcher("/WEBINF/admin/myjsp")forward(request response);}public void doPost(HttpServletRequest request HttpServletResponse response)throws ServletException IOException {thisdoGet(request response);}}
myjsp
<%@ page language="java" import="javautil*" pageEncoding="utf"%><! 引入jstl标签库 ><%@ taglib uri="%><!DOCTYPE html PUBLIC "//WC//DTD XHTML Transitional//EN" "<html> <head> <script type="text/javascript" language="javascript" src="js/js_deletejs" charset="gbk"></script> <link href="css/maincss" rel="stylesheet" type="text/css" /> <meta httpequiv="ContentType" content="text/html; charset=utf" /> <title>My JSP page</title> </head> <body> LIST:<select> <! 前提是已经把stus这个list放到了requestattribute中 在servlet或action中 requestsetAttribute(stus); > <c:forEach items="${stus}" var="stu"> <! Stu类中必须有set和get方法 > <option>${stuname}</option> </c:forEach> </select> </body></html>