一.学习的内容
1.JSP基本语法
(1)jsp脚本语法
(2)jsp声明语句
(3)jsp表达式
(4)jsp注释
2.jsp指令
(1)page指令
(2)include指令
3.jsp隐式对象(有九个)
3.代码实现:
(1)
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="java.util.Date" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
data.jsp
<%out.printn(new Date().toGMTString()); %>
</body>
</html>
(2)
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<%!
int a=1;
int b=3;
%>
<%!
public String daying(){
String str="dashuju2003";
return str;
}
%>
<%out.print("biaoda:" +a+b); %>
<br/>
<br/><br/>
<%out.print(daying()); %>
<br/><br/>
</body>
</html>
(3)
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<!-- html注释 -->
<%
System.out.print("java 注释");
%>
<%-- jsp注释 --%>;
</body>
</html>
(4)
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<%
out.print("frist line<br/>");
response.getWriter().print("second line<br/>");
%>
</body>
</html>
(5)
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<%
HttpServletRequest req=(HttpServletRequest)pageContext.getRequest();
pageContext.setAtteribute("req11","PAGE_SCOPE",pageContext.PAGE_SCOPE);
pageContext.setAtteribute("req22","PAGE_SCOPE",pageContext.PAGE_SCOPE);
pageContext.setAtteribute("req33","PAGE_SCOPE",pageContext.PAGE_SCOPE);
pageContext.setAtteribute("req","PAGE_SCOPE",pageContext.PAGE_SCOPE);
%>
<%=pageContext.findAttribte("req") %>
<hr/>
<%=(String)req.getAttribute("req") %>
</body>
</html>
(6)
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>欢迎您</title>
</head>
<body>
欢迎您,现在时间是:
<%@ include file="data .jsp" %>
</body>
</html>