读书人

JSTL1.1 lt;c:set target=quot;Beanquot;gt;的有关

发布时间: 2012-01-19 00:22:28 作者: rapoo

JSTL1.1 <c:set target="Bean"...>的问题
JavaBean

package jstlex;

public class Bean1 {
private String name;
private String age;

public Bean1() {
}

public void setName(String name) {
this.name = name;
}

public void setAge(String age) {
this.age = age;
}

public String getName() {
return name;
}

public String getAge() {
return age;
}
}


JSP

<%@ page contentType= "text/html; charset=GBK " %>
<%@ taglib uri= "http://java.sun.com/jsp/jstl/core " prefix= "c " %>
<jsp:useBean id= "userBean " scope= "session " class= "jstlex.Bean1 "/>
<html>
<head>
<title>
jsp1
</title>
</head>
<body bgcolor= "#ffffff ">
<c:set var= "name " target= "userBean " property= "name " value= "Lou "/>
<c:out value= "${name} "/> <br /> <!--可以输出Lou-->
<%=userBean.getName()%> <!--输出null-->
</body>
</html>

[解决办法]
<%@ page contentType= "text/html; charset=GBK " %>
<%@ taglib uri= "http://java.sun.com/jstl/core_rt " prefix= "c " %>
<%
String[] names={ "xu 23 ", "lou 23 "};
pageContext.setAttribute( "names ",names);
%>
<c:forEach var= "name " items= "${names} "> ${name} <br>
</c:forEach>

读书人网 >Java Web开发

热点推荐