zoukankan      html  css  js  c++  java
  • jsp中jstl标签的类似 if else 语句 的语法

    在jsp中引入jstl的标签库和函数库

    <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
    <%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>

    1. jsp中传递参数,经过action,存储到request中

    <area shape="poly" coords="680,111,765,82,811,196,724,223" 

     href="${pageContext.request.contextPath}/news/queryNews.do?artType=9&new=3" alt="摄影" title="摄影" />

    2. java代码中有

    String newFlag=request.getParameter("newFlag");
      if(newFlag!=null && !newFlag.equals("")){
       request.setAttribute("newFlag",newFlag);
      }

    3. jsp中的类似  if - else 语句 的语法

    <c:choose>
       <c:when test="${requestScope.newFlag== '1' || requestScope.newFlag== '2' ||requestScope.newFlag== '3'}"> 
             作品名称: ${star.class_}<br />
             作品编号: ${star.raceNum}<br />       
       </c:when>
       <c:otherwise>
         班级: ${star.class_}<br />
         参赛编号: ${star.raceNum}<br />
       </c:otherwise>
    </c:choose>

    1. 如果在jsp中传递参数,没有经过action ,直接跳转到jsp页面

    <a href="${pageContext.request.contextPath}/reg.jsp?newFlag=${requestScope.newFlag}">

    <img src="${pageContext.request.contextPath}/images/reg.png" width="76" height="53" alt="我要注册" title="我要注册" />

    </a>

    2. 在jsp中取得jsp传过来的参数,此时要使用${param.newFlag}

    <c:choose>
       <c:when test="${param.newFlag== '1' || param.newFlag== '2' ||param.newFlag== '3'}"> 
        <th>作品名称<font color="Red">*</font>:</th>      
       </c:when>
       <c:otherwise>
       <th>班级<font color="Red">*</font>:</th>
       </c:otherwise>
    </c:choose>

  • 相关阅读:
    修改Anaconda中Jupyter Notebook默认工作路径
    npm卸载和安装淘宝镜像原
    hash和history两种模式的区别
    威胁建模之WEB应用自动化截图
    Ubuntu系统清理
    Ubuntu环境的docker实践——ONOS
    BUUCTF-crypto:信息化时代的步伐
    BUUCTF-crypto:四面八方
    BUUCTF-crypto:[HDCTF2019]basic rsa
    BUUCTF-crypto:rsarsa
  • 原文地址:https://www.cnblogs.com/wanggd/p/3101788.html
Copyright © 2011-2022 走看看