当前位置: 代码迷 >> Java Web开发 >> JSTL1.1 <c:set target="Bean">的有关问题
  详细解决方案

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

热度:2868   发布时间:2016-04-17 16:15:04.0
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>
  相关解决方案