zoukankan      html  css  js  c++  java
  • <c:set/>实现计数器

    <%@ page language="java" contentType="text/html; charset=UTF-8"%>
    <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>
    </head>
    <body>

    <!-- 以下两个计数器,关键在于scope不同 -->
    <c:set var="totalCount" value="${ totalCount + 1 }" scope="application"></c:set>
    <c:set var="count" value="${ count + 1 }" scope="session"></c:set>
    本网站总访问人次:${ totalCount } <br/>
    其中您的访问次数:${ count } <br/>

    <!-- set支持标签体,value值可以写在value里,也可以写在标签体内 -->
    <c:set var="test" value="by value property"></c:set>
    <c:set var="test">by body</c:set>

    <br/>
    <br/>
    <br/>
    <br/>
    <%
    request.setAttribute("person", new com.helloweenvsfei.jstl.bean.Person()); // 创建person
    request.setAttribute("map", new java.util.HashMap()); // 创建Map
    %>

    <!-- target作用类似于var,不同的是target只能用来操作Java Bean或者Map。如果target为Java bean,则
    property为Java Bean的一个属性;如果target为Map,则property为Map的一个key-->
    <c:set target="${ person }" property="name" value="${ param.name }"></c:set>
    ${ person.name }

    <c:set target="${ map }" property="name" value="${ param.name }" />
    ${ map.name }

    </body>
    </html>

  • 相关阅读:
    一些tips
    微信小程序之后端处理
    微信小程序之前端代码篇
    微信小程序踩坑之前端问题处理篇
    Vue组件封装之一键复制文本到剪贴板
    读别人的代码之bug的发现
    解析webpack插件html-webpack-plugin
    数组去重方法整理
    如何理解EventLoop--浏览器篇
    axios和vue-axios的关系
  • 原文地址:https://www.cnblogs.com/Nickzerui/p/4546730.html
Copyright © 2011-2022 走看看