1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
<%@ page language=
"java"
import
=
"java.util.*"
pageEncoding=
"utf-8"
%>
<%@ taglib uri=
"http://java.sun.com/jsp/jstl/core"
prefix=
"c"
%>
<%
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
'index.jsp'
starting page</title>
<meta http-equiv=
"pragma"
content=
"no-cache"
>
<meta http-equiv=
"cache-control"
content=
"no-cache"
>
<meta http-equiv=
"expires"
content=
"0"
>
<meta http-equiv=
"keywords"
content=
"keyword1,keyword2,keyword3"
>
<meta http-equiv=
"description"
content=
"This is my page"
>
<!--
<link rel=
"stylesheet"
type=
"text/css"
href=
"styles.css"
>
-->
</head>
<body>
<%-- <!-- 静态获取 -->
<c:out value=
"helloworld"
></c:out>
<!-- 动态获取 -->
<%
request.getSession().setAttribute(
"username"
,
"lili"
);
%>
<c:out value=
"${3/2} "
></c:out>
<%
String username=
"username"
;
String username1=
""
;
request.setAttribute(
"username1"
, username1);
//放进requestScope对象里,用EL表达式取
request.setAttribute(
"username"
, username);
%>
<!--
false
-->
<c:out value=
"${empty username }"
></c:out><br>
<!--
true
-->
<c:out value=
"${empty username1 }"
></c:out><br>
<!--
true
-->
<c:out value=
"${empty user }"
></c:out><br>
<!-- 使用out标签输出常量 -->
<c:out value=
"hello World"
></c:out><br>
<!-- 使用out标签输出变量 -->
<%
request.getSession().setAttribute(
"name"
,
"li"
);
%>
<c:out value=
"${name }"
></c:out><br>
<!--
default
属性的使用 -->
<c:out value=
"${name1 }"
default
=
"error"
></c:out><br>
<!-- escapeXml="
true
属性设置是否转义,默认为
true
不转义-->
<c:out value=
"<out标签>"
escapeXml=
"false"
></c:out>
<!-- 表达式控制标签set标签,存值到scope中 -->
<c:set value=
"today"
var=
"day"
scope=
"session"
></c:set><br>
<!-- 输出day,值应该是today -->
<c:out value=
"${day }"
></c:out>
<!-- 表达式控制标签set标签,存值到scope中 -->
<c:set var=
"age"
scope=
"application"
>eleven</c:set><br>
<!-- 输出day,值应该是today -->
<c:out value=
"${age }"
></c:out>
<!-- 存值到javabean中 -->
<!-- 通过set向Person属性赋值 -->
<!-- 赋值和输出都要用EL表达式 --> --%>
<jsp:useBean id=
"person"
class
=
"com.imooc.entity.Person"
></jsp:useBean>
<c:set target=
"${person}"
property=
"age2"
value=
"12"
></c:set>
<%-- <c:out value=
"${person[age2]}"
></c:out> --%>
</body>
</html>
|
如果target="person",如下,会报如题异常!
1
|
<span style=
"color: #ff0000;"
><c:set target=
"person"
property=
"age2"
value=
"12"
></c:set></span><br><br><span style=
"color: #ff0000;"
>正常写法如下:</span>
|
1
|
<span style=
"color: #ff0000;"
><c:set target=
"${person}"
property=
"age2"
value=
"12"
></c:set></span>
|