我想在一个jsp文件中的一个组合框来显示一个servlet的arraylist传递,但是现在它在组合框的一行中显示整个arraylist . servlet代码
ArrayList<String> list = new ArrayList<String>();
list.add("A");
list.add("B");
list.add("C");
response.setIntHeader("default", 5);
request.setAttribute("name",":Motorola Solutions TC55");
request.setAttribute("item",list);
request.getServletContext().getRequestDispatcher("/default.jsp").forward(request, response);
jsp代码
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ 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="${item}" var="temp">
<option value='${temp}'>${temp}</option>
</c:forEach>
</select>
<button type="button" >Change Content</button>
</body>
</html>
我添加<%@ taglib uri = "http://java.sun.com/jsp/jstl/core" prefix = "c"%> now t无法在web.xml或使用此应用程序部署的jar文件中解析绝对uri:http://java.sun.com/jsp/jstl/core
2 回答
你错误地输入了arraylist的名字,
为避免上述错误,您应遵循standards的命名约定
错误在这里:
它应该是
最重要的是,我认为你可以't use the $ construct on request parameters. You'没有为"name"属性做到这一点 - 因为你已经使用
request.getAttribute
阅读了它,所以你需要在你的foreach中做到这一点