JSTL标签
<html> <body> <h2>Hello World!</h2> </body> </html> <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <html> <head> <title>c:if 标签实例</title> </head> <body> <c:set var="salary" scope="session" value="4000"/> <p>你的工资是 : <c:out value="${salary}"/></p> <c:remove var="salary"/> <p>删除 salary 变量后的值: <c:out value="${salary}"/></p> <c:import var="data" url="http://www.baidu.com"/> <!--<c:out value="${data}"/> --> <c:choose> <c:when test="${salary <= 0}"> 太惨了。<br> </c:when> <c:when test="${salary > 1000}"> 不错的薪水啊 <br> </c:when> <c:otherwise> 好好工作 <br> </c:otherwise> </c:choose> <c:forEach var="i" begin="1" end="5"> <c:choose> <c:when test="${i eq '1'}"> <c:out value="对应的值是1"></c:out> <br> </c:when> <c:when test="${i eq '2'}"> <c:out value="对应的值是2"></c:out><br> </c:when> <c:when test="${i eq '3'}"> <c:out value="对应的值是3"></c:out><br> </c:when> <c:when test="${i eq '4'}"> <c:out value="对应的值是4"></c:out><br> </c:when> <c:when test="${i eq '5'}"> <c:out value="对应的值是5"></c:out><br> </c:when> <c:otherwise> <c:out value="无对应的值"></c:out> </c:otherwise> </c:choose> </c:forEach>
<c:forEach var="i" begin="1" end="5"> <c:if test="${i<3}"> <c:out value="对应的值为${i}"></c:out> </c:if> </c:forEach> 对应的值为1 对应的值为2
<c:forTokens items="baidu,google,taobao" delims="," var="name"> <c:out value="${name}"></c:out> </c:forTokens> <c:url var="myURL" value="index.jsp"> <c:param name="name" value="Runoob"/> <c:param name="url" value="www.runoob.com"/> </c:url> <a href="/<c:out value="${myURL}"/>"> 使用 <c:param> 为指定URL发送两个参数。</a> <c:url var="testurl" value="index.jsp"> <c:param name="name" value="zhangsan"/> <c:param name="age" value="23"/> </c:url> <!-- http://localhost:8081/index.jsp?name=zhangsan&age=23--> <a href="/<c:out value="${testurl}"/>"> 使用 <c:param> 为指定URL发送两个参数。</a> <!-- --> <a href="<c:url value="http://www.baidu.com" />"> 点击跳转到百度首页 </a> <a href="<c:url value="http://www.runoob.com"/>"> 这个链接通过 <c:url> 标签生成。 </a> </body> </html>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ page import="java.io.*,java.util.*" %> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>菜鸟教程(runoob.com)</title> </head> <body> <h1>使用 GET 方法读取数据</h1> <ul> <li><p><b>站点名:</b> <%= request.getParameter("name")%> </p></li> <li><p><b>网址:</b> <%= request.getParameter("url")%> </p></li> </ul> <form action="index.jsp" method="GET"> 站点名: <input type="text" name="name"> <br /> 网址: <input type="text" name="url" /> <input type="submit" value="提交" /> </form> <html> <head> <title>自动刷新实例</title> </head> <body> <h2>自动刷新实</h2> <% // 设置每隔5秒刷新一次 response.setIntHeader("Refresh", 1); // 获取当前时间 Calendar calendar = new GregorianCalendar(); String am_pm; int hour = calendar.get(Calendar.HOUR); int minute = calendar.get(Calendar.MINUTE); int second = calendar.get(Calendar.SECOND); if(calendar.get(Calendar.AM_PM) == 0) am_pm = "AM"; else am_pm = "PM"; String CT = hour+":"+ minute +":"+ second +" "+ am_pm; out.println("当前时间为: " + CT + "\n"); %> <% Integer hitsCount = (Integer)application.getAttribute("hitCounter"); if( hitsCount ==null || hitsCount == 0 ){ /* 第一次访问 */ out.println("欢迎访问菜鸟教程!"); hitsCount = 1; }else{ /* 返回访问值 */ out.println("欢迎再次访问菜鸟教程!"); hitsCount += 1; } application.setAttribute("hitCounter", hitsCount); %> <p>页面访问量为: <%= hitsCount%></p> </body> </html> </body> </html>
无为而治