2017-02-20 51 views
0

我想根据数据库中的数据填充下拉列表的数量,例如,如果我有6条记录,我将生成6个下拉列表。请指定如何在提交后保留下拉列表中的值。保留jsp/servelts中下拉链接的选定值

<%@ page language="java" contentType="text/html; charset=UTF-8" 
 
    pageEncoding="UTF-8"%> 
 
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 
 
<%@page import="java.util.ArrayList,java.util.List" %> 
 
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
 
<html> 
 
<head> 
 
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
 
<title>Course Learning Objectives to Student Outcomes Mapper</title> 
 
</head> 
 
<body> 
 

 
<h1>Course Learning Objectives to Student Outcomes Mapper</h1> 
 

 
<c:choose> 
 

 
<c:when test="${empty id}"> 
 

 
<form method="get" action="CLOtoSO"> 
 

 
<select name="id"> 
 
<c:forEach items="${CourseIdMap}" var="Course"> 
 
    <option value="${Course.value}">${Course.key}</option> 
 
</c:forEach> 
 
</select> 
 
<input type="submit" value="Select" /> 
 
</form> 
 
</c:when> 
 

 
<c:otherwise> 
 

 
<table border="1"> 
 
<tr> 
 
    <td>&nbsp;</td> 
 
<c:forEach items="${SOIdsMap}" var="SOId"> 
 
<td title="${SODescriptionsMap[SOId.value]}">${SOId.key}</td> 
 
</c:forEach> 
 
</tr> 
 
<c:forEach items="${CLODescriptionsMap}" var="CLODescription"> 
 
<tr> 
 
<td>${CLODescription.value}</td> 
 
<c:forEach items="${SOIdsMap}" var="SOId"> 
 
    <td><select form="CLOtoSOform" name="map-${SOId.value}_${CLODescription.key}"> 
 
    
 
    <option value="-">-</option> 
 
    <option value="R">R</option> 
 
    <option value="I">I</option> 
 
    <option value="A">A</option> 
 
    </select></td> 
 
</c:forEach> 
 
</tr> 
 
</c:forEach> 
 
</table> 
 
<form method="post" action="CLOtoSO" id="CLOtoSOform"> 
 
    <input type="hidden" name="id" value="${id}"> 
 
    <input type="submit" value="Update" /> 
 
</form> 
 
</c:otherwise> 
 
</c:choose> 
 
</body> 
 
</html>

+0

您是否在提交表单后指下拉列表中的选定值? –

+0

是@VinothKrishnan – abhi

+0

我希望在第二个下拉列表中选定的值,即map - $ {SOId.value} _ $ {CLODescription.key}在提交后保留 – abhi

回答

0

当你提交的数据(选择下拉值)Servlet中,你可以把它回JSP为好。

我给样品一个下拉,

request.setAttribute("selectedId", request.getParameter("id")); 
RequestDispatcher rd = sc.getRequestDispatcher("/jsp/mypage.jsp"); 
rd.forward(request, response); 

request.getAttribute("selectedId") 

而在你的JSP页面查询request.getAttribute("selectedId")是真实的。 如果是这样做,

<c:forEach items="${SOIdsMap}" var="SOId"> 
    <select form="CLOtoSOform" name="map-${SOId.value}_${CLODescription.key}"> 
     <option value="${SOId.key}" ${SOId.key == selectedId ? 'selected="selected"' : ''}>${SOId.value}</option> 
    </select> 
</c:forEach> 

希望这可以帮助你。