一.ServletConfig和ServletContext
1.context使用场景
- 大部分的查询都具备分页功能
- 分页需要一个参数:每页显示几条数据size
- 该参数一般可配置,由于被众多查询功能复用,使用context读取
2.context可以存取变量
二.Servlet线程安全问题
三.include
/jsp1/src/main/webapp/hello.jsp
<%@page pageEncoding="utf-8"%>
<!doctype html>
<html>
<head>
<meta charset="utf-8"/>
<title>第1个JSP</title>
</head>
<body>
<!-- 3.jsp声明 -->
<%!
public double bai(double d) {
return d*100;
}
%>
<ul>
<!-- 1.jsp脚本 -->
<%
for(int i=0;i<10;i++) {
%>
<!-- 2.jsp表达式 -->
<li><%=bai(Math.random()) %></li>
<%
}
%>
</ul>
<%@include file="time.jsp"%>
</body>
</html>
/jsp1/src/main/webapp/time.jsp
<!--
pageEncoding: 声明此jsp文件的编码
contentType: 声明此jsp向浏览器输出的内容格式
-->
<%@page pageEncoding="utf-8"
contentType="text/html"
import="java.util.*,java.text.*"%>
<%
Date d = new Date();
SimpleDateFormat sdf =
new SimpleDateFormat("HH:mm:ss");
String time = sdf.format(d);
%>
<p><%=time %></p>
四.jsp原理
1.jsp处理请求的过程
2.jsp翻译的详细过程
五.jsp隐含/内置对象(笔试题)
1.request(*)
- HttpServletRequest
2.response
- HttpServletResponse
3.out
- JSPWriter
- 和PrintWriter一样
4.config
- ServletConfig
5.application
- ServletContext
6.exception
- Throwable
7.session(*)
- HttpSession
- 后面讲
8.page
- Object
- 就是this,指代jsp生成的那个Servlet
9.pageContext(*)
- PageContext
- 是一个管理者,通过它可以获得其他8个隐含对象
如何使用隐含对象?
- <%String user = request.getParameter(“user”);%>
- <%=request.getMethod()%>