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
Javascript 使用jsp向列表框添加项目_Javascript_Jsp_Servlets - Fatal编程技术网

Javascript 使用jsp向列表框添加项目

Javascript 使用jsp向列表框添加项目,javascript,jsp,servlets,Javascript,Jsp,Servlets,我是Servlets和Java的初学者,我想获得一些帮助,帮助我将项目从servlet添加到列表框中。我已尝试查找,但未成功。我想将多个项目添加到列表框中 this my servlet section String[] myStringArray = {"Motorola Solutions TC55","k35"}; response.setIntHeader("default", 5); request.setAttribute("name",":Mot

我是Servlets和Java的初学者,我想获得一些帮助,帮助我将项目从servlet添加到列表框中。我已尝试查找,但未成功。我想将多个项目添加到列表框中

  this my servlet section

 String[] myStringArray = {"Motorola Solutions TC55","k35"};
      response.setIntHeader("default", 5);
        request.setAttribute("name",":Motorola Solutions TC55");
        request.setAttribute("item","myStringArray");

        request.getServletContext().getRequestDispatcher("/default.jsp").forward(request, response);
这是我的JSP文件

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>


<!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>Include Manufacture name</title>
</head>
<body  >
<p id ="L1">Name :- <%=request.getAttribute("name")%></p>
<select>
<c:forEach items="${items}" var="item">
    <option value='${item}'>${item}</option>
</c:forEach>

</select>
<button type="button" >Change Content</button>
</body>
</html>
我只想将数组中的值添加到列表框中,您可以像使用smth一样

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

....

<c:forEach items="${items}" var="item">
    <option value='${item}'>${item}</option>
</c:forEach>
${items}数组包含选项列表

如果它们有不同的id和title字段,则如下所示

<c:forEach items="${items}" var="item">
    <option value='${item.id}'>${item.title}</option>
</c:forEach>

因此,在我的servlet id中,必须将item的属性设置为我希望它显示的wat?是的,例如,请参见此处-对不起,我不明白您的意思。您是否在页面顶部声明了taglib?