js| Visit | visit | check
This article will tell you how to access the list object through the Sun Company's JSTL tag and display it on a JSP page
In general, the list object is stored in the request object, in the Session object, and the framework (for example, action in the Struts framework) is used to put the list object into the Request object.
xxaction{
Public Actionforward Execute (
Actionmapping Mapping,
Actionform form,
HttpServletRequest request,
HttpServletResponse response) {
* * Get user information from session
HttpSession session=request.getsession ();
User user = (user) Session.getattribute ("User");
Request.setattribute ("user", user);
/* Establish rolelist*/
List rolelist =new ArrayList ();
for (int i=0;i<5;i++) {
Role role= The new role (I, the "role" +i);
Rolelist.add (role);
}
Request.setattribute ("Role_list", rolelist);
}
This article focuses on the JSTL label section:
<%@ taglib uri= "/jstl/core" prefix= "C"%>
<c:set var= "user" value= "${user}"/>
<tr bgcolor= "#FFFFFF" >
<TD align= "center" valign= "Top" >
<!--
Because of the problem with Chinese characters, you use the Struts tab to read the Adduser.role item in the resource file, the corresponding encoding is: role-->
<bean:message key= "Adduser.role"/></td>
<td>
<select name= "Role" >
<c:foreach var= "ro" items= "${role_list}" ><!--access to the Role_list object in the request-->
<c:choose>
<c:when test= "${user.role==ro.role_name}" ><!--, equivalent to if (User.getrole (). Equlas (Rolgetrolename ()) If the role in the user is the same as the role in the list, select (highlight) in the Select-->
<option selected= "Selected"
Value= "<c:out value=" ${ro.role_id} "/>" ><!--Set the value item so that you see the name in the page, and when selected
After that, the receiver is actually id-->.
<c:out value= "${ro.role_name}"/><!--see role_name-->.
</option>
</c:when>
<c:otherwise><!--equivalent to else-->
<option value= "<c:out value=" ${ro.role_id} "/>" >< principle of!---ditto-->
<c:out
Value= "${ro.role_name}" ></c:out></option>
</c:otherwise>
</c:choose>
</c:forEach><!--Cycle end-->
</select></td>
</tr>
Mutual encouragement, welcome Exchange:wyf_cjl@sohu.com