日期:2014-05-17  浏览次数:20698 次

咨询个简单的jstl jsp里标签的用法
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>  
<%@ taglib uri="http://java.sun.com/jstl/fmt_rt" prefix="fmt" %> 
头部包含了这2个

<c:choose>

       <c:when test="<%=product_price%> ==0">

              电讯

       </c:when>

    <c:otherwise>  
              <%=product_price%>

       </c:otherwise>  

</c:choose>   



 <%=product_price%>
是输出的变量值  ,上面这段报错  <c:when test="<%=product_price%> ==0">
这句话赋值判断报错 attribute value,我知道应该变量赋值错误了,但不知道这个变量判断怎么写,对jsp不太熟悉,知道的帮下忙吧,这句话的作用的就当 <%=product_price%>
这个值为0时显示  电讯 ,不为 0时正常显示,我知道很简单。
JSP 标签 jstl

------解决方案--------------------
引用:
上面这个代码 我放上去试了下  product_price因为已经取到值了,就只放了  
 <c:choose>
 
       <c:when test="<%=product_price ==3%>">
 
              This is my JSP page. <br>
 
       </c:when>
 
    <c:otherwise>  
               <%=product_price%>
 
       </c:otherwise>  
 
</c:choose>   

报错Incompatible operand types String and int  不相容的数据类型,如果前面加上 <%int product_price; %>  这行就会报错

我这个例子就是证明了<c:whew> ……<c:orherwise>....能用,你那种情况看具体代码好解决,因为你的product_price可能是从servlet等其他地方传过来的,都不知道是什么类型。还有如果前面加上 <%int product_price; %>没有初始化应该默认为0吧,还要考虑会不会跟你从servlet等其他地方传过来的product_price有冲突呢。注意断点,单步调试。