springmvc中的jsp页面<c:if>的使用
2015-03-24 11:03
357 查看
首先看一个实实在在的项目文档
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!doctype html>
<html lang="zh-cn">
<head>
<base href="<%=basePath%>">
<meta charset="UTF-8">
<meta name="Keywords" content="种筹天下" />
<meta name="Description" content="种筹天下" />
<title>种筹天下</title>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1,user-scalable=ture">
<link rel="stylesheet" href="m/css/other.css">
</head>
<body>
<!-- <div id="header">
<div class="header_left_btn">
<a href="javascript:window.history.go(-1);"><img src="m/images/back.png" height="28"></a>
</div>
<p class="header_tt">搜索结果</p>
</div> -->
<div id="main">
<div class="search_box">
<c:if test="${! empty testUnit.crop_name}"><p class="search_p clearfix"><span class="search_left" style="width:30%"><font color=green>【作物名称】</font></span><span class="search_right" style="width:65%">${testUnit.crop_name }</span></p></c:if>
<c:if test="${! empty testUnit.service_item}"><p class="search_p clearfix"><span class="search_left" style="width:30%"><font color=green>【服务项目】</font></span><span class="search_right" style="width:65%">${testUnit.service_item } ${testUnit.service_item_son }</span></p></c:if>
<c:if test="${! empty testUnit.method}"><p class="search_p clearfix"><span class="search_left" style="width:30%"><font color=green>【测试方法】</font></span><span class="search_right" style="width:65%">${testUnit.method }</span></p></c:if>
<c:if test="${! empty testUnit.wait_data}"><p class="search_p clearfix"><span class="search_left" style="width:30%"><font color=green>【等待时间】</font></span><span class="search_right" style="width:65%">${testUnit.wait_data }</span></p></c:if>
<c:if test="${! empty testUnit.cost}"><p class="search_p clearfix"><span class="search_left" style="width:30%"><font color=green>【费用】</font></span><span class="search_right" style="width:65%">${testUnit.cost }</span></p></c:if>
<c:if test="${! empty testUnit.name}"><p class="search_p clearfix"><span class="search_left" style="width:30%"><font color=green>【单位名称】</font></span><span class="search_right" style="width:65%">${testUnit.name }</span></p></c:if>
<c:if test="${! empty testUnit.address}"><p class="search_p clearfix"><span class="search_left" style="width:30%"><font color=green>【地址】</font></span><span class="search_right" style="width:65%">${testUnit.address }</span></p></c:if>
<c:if test="${! empty testUnit.contactor}"><p class="search_p clearfix"><span class="search_left" style="width:30%"><font color=green>【联系人】</font></span><span class="search_right" style="width:65%">${testUnit.contactor }</span></p></c:if>
<c:if test="${! empty testUnit.phone_number}"><p class="search_p clearfix"><span class="search_left" style="width:30%"><font color=green>【电话】</font></span><span class="search_right" style="width:65%">${testUnit.phone_number }</span></p></c:if>
<c:if test="${! empty testUnit.introduction}"><p class="search_p clearfix"><span class="search_tt"><font color=green>【测试单位简介】</font></span></p>
<p class="search_p clearfix"><span class="search_tt">${testUnit.introduction}</span></p></c:if>
<p class="search_p clearfix"><span class="search_left" style="width:30%"><font color=green>【国家】</font></span><span class="search_right" style="width:65%">${testUnit.country }</span></p>
<p class="search_p clearfix"><span class="search_left" style="width:30%"><font color=green>【地区】</font></span><span class="search_right" style="width:65%">${testUnit.area_province } ${testUnit.area_city } ${testUnit.area_county }</span></p>
<c:if test="${! empty testUnit.picture}"><p class="search_p clearfix"><span class="search_tt"><font color=green>【相关图片】</font></span></p>
<table width="90%" border="0" cellspacing="0" cellpadding="0" style="margin:12px auto 50px;">
<c:set value="${fn:split(testUnit.picture,';')}" var="pictures" />
<c:forEach items="${pictures }" var="pict" varStatus="s">
<tr>
<td ><img width="100%" height="65%" src="${pict }"></td>
</tr>
<tr>
<td> </td>
</tr>
</c:forEach>
</table>
</c:if>
</div>
</div>
</body>
</html>
总结一下其中的<c:if>的使用:
<c:if test="${! empty testUnit.crop_name}"><p class="search_p clearfix"><span class="search_left" style="width:30%"><font color=green>【作物名称】</font></span><span class="search_right" style="width:65%">${testUnit.crop_name }</span></p></c:if>
意思是,如果testUnit.crop_name这个变量名称不为空的话,就显示出来,如果为空的话,就不显示。
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!doctype html>
<html lang="zh-cn">
<head>
<base href="<%=basePath%>">
<meta charset="UTF-8">
<meta name="Keywords" content="种筹天下" />
<meta name="Description" content="种筹天下" />
<title>种筹天下</title>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1,user-scalable=ture">
<link rel="stylesheet" href="m/css/other.css">
</head>
<body>
<!-- <div id="header">
<div class="header_left_btn">
<a href="javascript:window.history.go(-1);"><img src="m/images/back.png" height="28"></a>
</div>
<p class="header_tt">搜索结果</p>
</div> -->
<div id="main">
<div class="search_box">
<c:if test="${! empty testUnit.crop_name}"><p class="search_p clearfix"><span class="search_left" style="width:30%"><font color=green>【作物名称】</font></span><span class="search_right" style="width:65%">${testUnit.crop_name }</span></p></c:if>
<c:if test="${! empty testUnit.service_item}"><p class="search_p clearfix"><span class="search_left" style="width:30%"><font color=green>【服务项目】</font></span><span class="search_right" style="width:65%">${testUnit.service_item } ${testUnit.service_item_son }</span></p></c:if>
<c:if test="${! empty testUnit.method}"><p class="search_p clearfix"><span class="search_left" style="width:30%"><font color=green>【测试方法】</font></span><span class="search_right" style="width:65%">${testUnit.method }</span></p></c:if>
<c:if test="${! empty testUnit.wait_data}"><p class="search_p clearfix"><span class="search_left" style="width:30%"><font color=green>【等待时间】</font></span><span class="search_right" style="width:65%">${testUnit.wait_data }</span></p></c:if>
<c:if test="${! empty testUnit.cost}"><p class="search_p clearfix"><span class="search_left" style="width:30%"><font color=green>【费用】</font></span><span class="search_right" style="width:65%">${testUnit.cost }</span></p></c:if>
<c:if test="${! empty testUnit.name}"><p class="search_p clearfix"><span class="search_left" style="width:30%"><font color=green>【单位名称】</font></span><span class="search_right" style="width:65%">${testUnit.name }</span></p></c:if>
<c:if test="${! empty testUnit.address}"><p class="search_p clearfix"><span class="search_left" style="width:30%"><font color=green>【地址】</font></span><span class="search_right" style="width:65%">${testUnit.address }</span></p></c:if>
<c:if test="${! empty testUnit.contactor}"><p class="search_p clearfix"><span class="search_left" style="width:30%"><font color=green>【联系人】</font></span><span class="search_right" style="width:65%">${testUnit.contactor }</span></p></c:if>
<c:if test="${! empty testUnit.phone_number}"><p class="search_p clearfix"><span class="search_left" style="width:30%"><font color=green>【电话】</font></span><span class="search_right" style="width:65%">${testUnit.phone_number }</span></p></c:if>
<c:if test="${! empty testUnit.introduction}"><p class="search_p clearfix"><span class="search_tt"><font color=green>【测试单位简介】</font></span></p>
<p class="search_p clearfix"><span class="search_tt">${testUnit.introduction}</span></p></c:if>
<p class="search_p clearfix"><span class="search_left" style="width:30%"><font color=green>【国家】</font></span><span class="search_right" style="width:65%">${testUnit.country }</span></p>
<p class="search_p clearfix"><span class="search_left" style="width:30%"><font color=green>【地区】</font></span><span class="search_right" style="width:65%">${testUnit.area_province } ${testUnit.area_city } ${testUnit.area_county }</span></p>
<c:if test="${! empty testUnit.picture}"><p class="search_p clearfix"><span class="search_tt"><font color=green>【相关图片】</font></span></p>
<table width="90%" border="0" cellspacing="0" cellpadding="0" style="margin:12px auto 50px;">
<c:set value="${fn:split(testUnit.picture,';')}" var="pictures" />
<c:forEach items="${pictures }" var="pict" varStatus="s">
<tr>
<td ><img width="100%" height="65%" src="${pict }"></td>
</tr>
<tr>
<td> </td>
</tr>
</c:forEach>
</table>
</c:if>
</div>
</div>
</body>
</html>
总结一下其中的<c:if>的使用:
<c:if test="${! empty testUnit.crop_name}"><p class="search_p clearfix"><span class="search_left" style="width:30%"><font color=green>【作物名称】</font></span><span class="search_right" style="width:65%">${testUnit.crop_name }</span></p></c:if>
意思是,如果testUnit.crop_name这个变量名称不为空的话,就显示出来,如果为空的话,就不显示。
相关文章推荐
- 如何在JSP页面中使用JSTL标签实现if和if-else判断,判断条件使用<%=value%>
- Jsp 页面迭代中使用<s:if>判断动态变量值
- jsp页面使用表达式<%=basePath%>跳转报“ attribute for %> is not properly terminated”错误
- struts2中ognl表达式%$#在jsp页面的使用总结以及<s:a title=%{title}>的作用
- jsp页面,使用Struts2标签,传递和获取Action类里的参数,注意事项。<s:a action><s:iterator><s:param>ognl表达式 在编写SSH2项目的时候,除
- 在jsp页面中使用<c:if标签比较两个值
- 关于eclipse Oxygen 版本的JSP页面中option里面写<c:if>嵌套时报错
- spring3 jsp页面使用<form:form modelAttribute="xxxx" action="xxxx">报错,附连接数据库的spring MVC annotation 案例
- JSP <c:if>和<c:foreach>简单使用
- 在Jsp中使用<s:if test="">,条件的值是action中设置的session的值
- jsp页面中时间格式化显示,<fmt:formatDate> 标签使用
- 在WEB-INF下的某个页面里使用<jsp:include page="/WEB-INF/personal/yhhead.jsp">,竟然可以访问到
- jsp页面中的<c:if test="">中的<%= %>判断是否相等
- jsp页面中使用<s:debug></s:debug>标签报错
- jsp页面中使用了<%=new java.util.Date()>但是不显示效果
- jsp页面中使用jstl的< c:choose> <c:when><c:otherwise>错误
- struts2 jsp页面访问List, set 和<s:iterator>的使用
- jsp页面动态展示list-使用<select>和<c:forEach>标签
- spring3 jsp页面使用<form:form modelAttribute="xxxx" action="xxxx">报错,附连接数据库的spring MVC annotation 案例
- JSP中使用<c:if>使用后台参数