天天看点

Jstl标签库

Jstl标签库

自定义标签库

Mvc设计模式

Java三层框架

Jstl概述

Apache提供的,必须要导入jar包

Core 核心标签库,c标签

<c:out>输出

1value:可以是字符串常量,也可以是el表达式

2default:当要输出的内容为null时,会输出default指定的值。

3escapeXml:默认为true ,表示转义。

<c:set>

1var:变量名

2value:变量值可以为el表达式

3scope:默认为page,可选值page,request,Session,application

Remove删除域变量

Var变量名

Scope如果不给出scope,表示删除所有域中的该名称的变量,如果指定了域,那么只删除该域的变量。

url

value指定一个路径!给他会在路径前面自动添加项目名

可以给url后面添加参数

<c:param>name value

Var 指定变量名,,一旦加入这个属性,那么url标签就不会在输出到页面,而是把生成url保存到域中

Scope它与var一起使用,用来保存url。

If语句

<c:if test="布尔类型">…</c:if>:当test为真时执行标签体内容

Choose语句

<c:choose>

<c:when test="">…</c:when>

<c:otherwise></c:otherwise>

</c:choose>

Foreach

<c:forEach var="i" begin="i" end="10" syep="2">${i}

</c:forEach>

Items要便利的是集合

Var把数组或集合中的每个元素复制给var指定的变量。

循环状态varstatus 来创建循环状态变量。

Count

Index

First

Last

Current当前元素

代码

<%@

page

language="java"

import="java.util.*"

pageEncoding="UTF-8"%>

taglib

prefix="c"

uri="http://java.sun.com/jsp/jstl/core"

%>

<%

String path = request.getContextPath();

String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

%>

<!DOCTYPE HTML

PUBLIC

"-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

<head>

<base

href="<%=basePath%>">

<title>My JSP '2.jsp' starting page</title>

    <meta

http-equiv="pragma"

content="no-cache">

http-equiv="cache-control"

http-equiv="expires"

content="0">

http-equiv="keywords"

content="keyword1,keyword2,keyword3">

http-equiv="description"

content="This is my page">

    <!--

    <link rel="stylesheet" type="text/css" href="styles.css">

    -->

</head>

<body>

This is my JSP page. <br>

<c:set

var="code"

value="<script>alert('hello');</script>"

scope="request"/>

<c:out

value="${code }"

escapeXml="true"/><br>

<c:url

value="/Aservlet"/><br>

${pageContext.request.contextPath }/Aservlet

<a

href="<c:url value='/index.jsp'">点击此处回到主页</a>

<br>

    <c:url

value='/indfex.jsp'>

        <c:param

name="name"

value="张三"></c:param>

    </c:url>

    <hr>

    <c:if

test="${empty param.name }">

        您没有给出名为name的参数!

    </c:if>

    <c:choose>

        <c:when

test="${empty param.name }">您没有给出名为name的参数</c:when>

        <c:otherwise>谁让你给出name参数的!${param.name }</c:otherwise>

    </c:choose>

    <c:forEach

var="i"

begin="1"

end="10"

step="2">

        ${i }<br>

    </c:forEach>

    <%String []strs={"one","two"};

        request.setAttribute("strs", strs);

    %>

items="${strs }"

var="str">

        ${str }<br>

    <%

    ArrayList<String> list=new ArrayList<String>();

    list.add("一");

    list.add("二");

    list.add("三");

    pageContext.setAttribute("list", list);

items="${1list }"

var="ele"

varStatus="vs">

        ${vs.index }${vs.count }${vs.first }${vs.last }${vs.current }<br>

</body>

</html>

Fmt标签库

格式化

<fmt:formatData value="${d}" partten="yyyy-MM-dd HH:mm:ss"/>

<fmt:formatNumber value="${number}" partten=""/>

0.00保留小数点位数,四舍五入

不足补零

#.##不补位数

自定义标签

Mvc设计模式

他不是Java独有的,所有的b/s结构的项目都在使用它

M model模型(自己写代码)

V view 视图(jsp)

C control控制器(servlet)

不只是一个。

上一篇: 读后感
下一篇: Ajax的使用