<c:if test="${customercity.code==selectCity}">
解决方案 »
- 急!!数据库表中不插入重复数据的处理 100分哦
- Hibernate bag标签的使用
- 关于MVC模式的实践问题
- 怎样找出包含在HttpSession,Request,ThreadLocal中的对象
- 发送邮件验证信息后,跟踪邮件是否是用户复制到ie上还是在邮件里直接打开的?
- 在线等 JAVA(JSP相关)和域控制器的问题~~~
- hibernate映射oracle 序列问题!!
- 急问struts中treeview中显示问题,恳请struts中做过treeview的高手提醒!!
- [迷惑]Java学到什么程度才适合接触EJB?
- sql 语句
- Hibernate问题
- java中将临时表插入到新临时表出的错误 急!急!急!急!急!急!急!
我有一个option想当值等于selectCity时选中,下面这样为什么不行?
<select name="city">
<c:forEach var="customercity" items="${city}">
<c:if test='${customercity.code==selectCity}'>
<option value="<c:out value='${customercity.code}'/>" selected><c:out value="${customercity.name}"/></option>
</c:if>
<c:if test='${customercity.code!=selectCity}'>
<option value="<c:out value='${customercity.code}'/>"><c:out value="${customercity.name}"/></option>
</c:if>
</c:forEach>
</select>
这符合JSP1.2与JSTL1.0规范,可以在Tomcat4.1上运行。不过,也是有前提的:
1. 已经使用过request.setAttribute("city", city)
2. 已经使用过request.setAttribute("selectCity", selectCity)
3. city是一个集合(比如List或Set)或对象数组,该集合内的那个Object(customercity)有code和name属性,并且有对应的public型的getCode()与getName()方法
4. 我自己编程时,全是双引号,不必用单引号。此外,如果你的Web容器(比如Tomcat5.5)支持JSP2.0规范,还可以简化为:
<select name="city">
<c:forEach var="customercity" items="${city}">
<c:if test="${customercity.code==selectCity}">
<option value="${customercity.code}" selected>${customercity.name}</option>
</c:if>
<c:if test="${customercity.code!=selectCity}">
<option value="${customercity.code}">${customercity.name}</option>
</c:if>
</c:forEach>
</select>