Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jsp 通过JSTL从数据库动态填充下拉菜单_Jsp_Jstl_Jsp Tags - Fatal编程技术网

Jsp 通过JSTL从数据库动态填充下拉菜单

Jsp 通过JSTL从数据库动态填充下拉菜单,jsp,jstl,jsp-tags,Jsp,Jstl,Jsp Tags,我的web应用有以下设置: 1.)一个Bean类。 2.)返回包含Bean的arraylist的DAO类。 3.)具有下拉菜单的JSP页面 我需要从步骤2中创建的arraylist填充此下拉菜单。我对JSTL了解不多。我设法通过Scriptlet填充我的下拉列表(使用for-each循环并迭代存储在会话中的arraylist)。 现在我需要从Scriptlet中释放代码。我应该学习JSTL还是使用AJAX(或jquery)?如果我计划使用标记,我是否需要首先调用servlet来返回arrayli

我的web应用有以下设置:

1.)一个Bean类。
2.)返回包含Bean的arraylist的DAO类。
3.)具有下拉菜单的JSP页面

我需要从步骤2中创建的arraylist填充此下拉菜单。我对JSTL了解不多。我设法通过Scriptlet填充我的下拉列表(使用for-each循环并迭代存储在会话中的arraylist)。
现在我需要从Scriptlet中释放代码。我应该学习JSTL还是使用AJAX(或jquery)?如果我计划使用
标记,我是否需要首先调用servlet来返回arraylist?


<select>
     <c:forEach var="item" items="${list}">
          <option><c:out value="${item}"/></option>
     </c:forEach>
</select> 

关于你的第二个问题。是的,您可以调用request.setAttribute(…)并使用RequestDispatcher转发到JSP页面,该页面随后使用useBean标记。

因此,例如,如果我从servlet转发名为“dlist”的arraylist,并且我的bean的属性是“name”和“age”,那么我的标记将是正确的吗?是的,这是正确的。只需确保该属性也称为dlist:request.setAttribute(“dlist”,dlist);