在JSTL中输出表单数据(仅限一个记录)

时间:2014-04-16 21:50:31

标签: java jstl cout

我需要做的只是输出一个客户,而不是一个客户列表。 foreach将为每个输入的custoemr工作,但我只需要刚刚输入的客户。我使用<:cout>有价值的东西或我如何实现这个目标?

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<c:forEach items="${requestScope.customers}" var="customer">
<c:out value="${customer.firstName }"/>
</c:forEach>

</body>
</html>

1 个答案:

答案 0 :(得分:0)

如果您只想显示一个对象,则不需要<c:forEach>。 您可以在请求范围内设置对象,并使用<c:out>

打印值
<c:out value="${customer.firstName}"/>

假设您在控制器中设置了类似的内容

request.setAttribute("customer", customerObject);