101-servlet生命周期方法
当tomcat关闭的时候 servlet会销毁.
alt+/ 可以看到所有能重写的方法.
101-servlet生命周期方法
当tomcat关闭的时候 servlet会销毁.
alt+/ 可以看到所有能重写的方法.
102-jar包引入和web配置文件创建
103-page和pageContext内置对象
page对象 只对当前的页面起作用.
四大域对象: page, request, session, application(注意区分作用域)
104-乱码问题解决和jspinclude
request.setCharacter/encoding("utf-8"); 即可解决乱码.
<jsp:include page="head.jsp"></jsp:include>
105-客户端的绝对路径问题
<% request.getContextPath()%> 获取当前的项目名.
106-客户端的相对路径问题
绝对路径就是从当前项目根目录开始找
客户端路径是浏览器解析的.
在客户端路径一般都不会写相对路径.
107-服务器端路径的问题
看能不能把在浏览器上显示出来, 能的话就是客户端路径, 不能就是服务器端路径.
客户端路径统一使用绝对路径.
客户端绝对路径: http://localhost8080/
服务器端绝对路径: http://localhost8080/web04/
EL表达式
request session application....
<%request.setAttribute("number", 50000);
%>
${number}
108-单例模式
public static JDBCUtil instance= new JDBCUtil();
JDBCUtil.instance.GetConnection();
可以把构造方法私有化,防止在外面使用构造方法.
EL表达式
<%request.setAttribute("hello", 50000);
%>
${requestScope.hello }
${hello }
JSTL jsp标签库
jsp标签
html标签
其它标签
111-创建数据模型和模拟数据库
static静态代码块,当web项目被加载的时候, 会自动先执行.
导入jstl标签
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
JSTL相关用法
dispatcher 标签 :设置过滤请求的类型
有4中常用的类型:REQUEST FORWARD
INCLUDE ERROR
REQUEST:默认的 常用的请求
forward:请求的转发 request.getRequestDispatcher("index.jsp").forward(request,response);
INCLUDE:页面的包含 JSP代码:<jsp:include page="index.jsp"></jsp:include>
ERROR:页面出错 可以指定 跳转到某个页面
<error-page>
<error-code>出错误的类型(404)</error-code>
<location>/index.jsp(指定出错误跳转到的页面)</location>
</error-page>
jstl表达式中if else 语句如下:
<c:set var="age" value="25" scope="request"></c:set>
<c:choose>
<c:when test="${age>=16 }">
<font color="green">你是成年人</font>
</c:when>
<c:otherwise>
<font color="rad">你未成年</font>
</c:otherwise>
</c:choose>
JSTL语句中的循环表达式:
取数据的时候都需要用到EL表达式${}来取值如:
例1
<c:forEach begin="1" end="15">
<%out.println("正在执行foreach语句"); %>
</c:forEach>
例2
<%
UserDao.addUser("A", new User("A", "男", 31, "shibin123", true));
UserDao.addUser("B", new User("B", "女", 32, "shibin123", true));
UserDao.addUser("C", new User("C", "女", 23, "shibin123", true));
UserDao.addUser("D", new User("D", "女", 34, "shibin123", true));
UserDao.addUser("E", new User("E", "女", 21, "shibin123", true));
UserDao.addUser("F", new User("F", "女", 23, "shibin123", true));
UserDao.addUser("G", new User("G", "男", 24, "shibin123", true));
Map ma=DBUtil.getUsers();
List list=new ArrayList();
list.addAll(ma.values());
request.setAttribute("list", list);
%>
<c:forEach items="${list }" var="us">
${us.name},${us.age},${us.sex},${us.password}<br>
</c:forEach>
$(function(){
$("imput[name='username']").blur(verifyUsername);
属性选择器,失去焦点调用verifyUsername
});
监听器能监听相应的值deng
域对象
request session application
类型
HttpServletRequest HttpSession ServletContext
116-处理登录成功后的跳转
注意请求转发和重定向的不同.