jsp 怎么写

jsp尽量不要写java代码,所以出现了现在的EL表达式 ${}这种类型。

上古时期写法(java代码和html代码直接混合写)
 <body>
   	<h1>购物车</h1>
   	<table border="1">
   		<tr>
			<th>商品名称</th>
			<th>商品数量</th>
   		</tr>
   		<%
   			Map<String,Integer> cart = (Map<String,Integer>)session.getAttribute("cart");
   			if(cart!=null && cart.size()>0){
   				for(Entry<String,Integer> en : cart.entrySet()){
   				%>
   				<tr>
					<td><%=en.getKey() %></td>
					<td><%=en.getValue() %></td>
		   		</tr>
   				<% }
   			}
   		 %>
   	</table>
  </body>


现代写法(JSTL标签)

<table border="1">
    	<tr>
    		<th>用户名</th>
    		<th>当前遍历索引</th>
    		<th>当前遍历计数</th>
    		<th>是否是集合第一个元素</th>
    		<th>是否是集合最后一个元素</th>
    	</tr>
	     <c:forEach items="${list}" var="name" varStatus="st" >
		    <tr class="${st.index%2==0?"one":"two"}" >
	    		<td>${name}</td>
	    		<td>${st.index}</td>
	    		<td>${st.count}</td>
	    		<td>${st.first}</td>
	    		<td>${st.last}</td>
	    	</tr>
	    </c:forEach>
    </table>
<hr> 
	<!--  数数的功能-->
	<c:forEach begin="1" end="10" step="1" var="num" >
		${num}
	</c:forEach>




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值