文章目录
`
一、Servlet
Servlet原理
Mapping问题
ServletContext
HttpServeletResponse
1.简单分类 下载文件 验证码功能 实现重定向 Request应用
cookie session
public class Cookiedemo extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
req.setCharacterEncoding("utf-8");
resp.setCharacterEncoding("utf-8");
PrintWriter out = resp.getWriter();
Cookie[] cookies = req.getCookies();
if(cookies!=null){
out.write("上一次访问");
for (int i = 0; i <cookies.length; i++) {
Cookie cookie = cookies[i];
if (cookie.getName().equals("last")){
cookie.getValue();
long l = Long.parseLong(cookie.getValue());
Date date=new Date(l);
out.write(date.toLocaleString());
}
}
}else {
out.write("这是第一次");
}
Cookie cookie = new Cookie("last", System.currentTimeMillis()+"");
resp.addCookie(cookie);
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
super.doPost(req, resp);
}
}
req.setCharacterEncoding("utf-8");
resp.setCharacterEncoding("utf-8");
resp.setContentType("text/html; charset=utf-8");
HttpSession session=req.getSession();
session.setAttribute("naem","张三");
String id=session.getId();
if(session.isNew()){
resp.getWriter().write("成功"+id);
}else{
resp.getWriter().write("存在"+id);
}
JSPhttps://www.runoob.com/jsp/jsp-session.html
JAVABean
M V C
过滤器 Filter
监听器
三、当你的浏览器中地址栏输⼊地址并回车的⼀瞬间到页⾯能够展⽰
回来,经历了什么
1.浏览器会先在本地的host找出对应的域名,浏览器向DNS服务器查找输⼊的url对应的ip地址
2、DNS服务器返回⽹站的IP地址
3、浏览器根据IP地址与⽬标web服务器在80端⼝上建⽴TCP连接
4、浏览器获取请求页⾯的html代码
5、浏览器显⽰窗⼝内渲染html
6、窗⼝关闭时,浏览器停⽌与服务器的连接