review:
1. post提交方式下的设置编码,防止中文乱码
request.setCharacterEncoding("utf-8");
get提交方式,tomcat8开始,编码不需要设置
tomcat8之前,get方式设置比较麻烦:
String fname = request.getParameter("fname");
byte[] bytes = fname.getBytes("iso-8859-1");
fname = new String(bytes,"UTF-8");
2. Servlet继承关系以及生命周期
1) Servlet接口 : init() , service() , destroy()
GenericServlet抽象子类: abstract service();
HttpServlet抽象子类:实现了service方法,在service方法内部通过request.getMethod()来判断请求的方式,
然后根据请求的方式去调用内部的do方法。每一个do方法进行了简单实现,主要是如果请求方式不符合,则报405错误。
目的是让我们的Servlet子类去重写对应的方法(如果重写的不对,则使用父类的405错误实现)
2) 生命周期:实例化、初始化、服务、销毁
- Tomcat负责维护Servlet实例的生命周期
- 每个Servlet在Tomcat容器中只有一个实例,它是线程不安全的
- Servlet的启动时机:<load-on-startup>
- Servlet3.0开始支持注解: @WebServlet
3. HTTP协议:
1) 由 Request 和 Response 两部分组成
2) 请求包含了三部分:请求行、请求消息头、请求主体: 普通的get方式请求-query string;post方式- form data ; json格式 - request payload
3) 响应包含了三部分:响应行、响应消息头、响应主体
4. HttpSession
1) HttpSession :表示 会话
2) 为什么需要HttpSession , 原因是因为 Http协议是无状态的
3) Session保存作用域 :一次会话范围都有效 ; void session.setAttribute(k,v) ,Object session.getAttribute(k)
4) 其他的API: session.getId() , session.isNew() , session.getCreationTime() , session.invalidate() 等等
5. 服务器端转发和客户端重定向
1) 服务器端转发 : request.getRequestDispatcher("index.html").forward(request,response);
2) 客户端重定向: response.sendRedirect("index.html");
6. thymeleaf的部分标签
1) 使用步骤: 添加jar;新建一个基类ViewBaseServlet(有两个方法);配置两个<context-param> : view-prefix , view-suffix
2) 部分标签: <th:if> , <th:unless> , <th:each> , <th:text>
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
java web 一个简陋的网站页面 (153个子文件)
BaseDAO.class 8KB
BaseDAO.class 8KB
AddByAnnotationServlet.class 3KB
AddByAnnotationServlet.class 3KB
AddStuByAnnotationServlet.class 3KB
AddStuByAnnotationServlet.class 3KB
FruitServlet.class 3KB
FruitServlet.class 3KB
ViewBaseServlet.class 3KB
ViewBaseServlet.class 3KB
Fruit.class 2KB
Fruit.class 2KB
CharacterEncodingFilter.class 2KB
CharacterEncodingFilter.class 2KB
Student.class 2KB
Student.class 2KB
DemoServlet.class 2KB
DemoServlet.class 2KB
AddByWebServlet.class 2KB
AddByWebServlet.class 2KB
Demo02Servlet.class 2KB
Demo02Servlet.class 2KB
Demo01Filter.class 1KB
Demo01Filter.class 1KB
FruitDaoImpl.class 1KB
FruitDaoImpl.class 1KB
Main.class 1KB
Main.class 1KB
HelloServlet.class 1KB
HelloServlet.class 1KB
IBaseDAO.class 242B
IBaseDAO.class 242B
demo05.css 998B
demo05.css 998B
demoInfo.css 973B
demoInfo.css 973B
style.css 254B
style.css 254B
.gitignore 344B
demo01.html 2KB
demo01.html 2KB
demo03.html 2KB
demo03.html 2KB
demo02.html 2KB
demo02.html 2KB
demo10.html 2KB
demo10.html 2KB
studentCss.html 2KB
studentCss.html 2KB
demoFruit_annotation.html 2KB
demoFruit_annotation.html 2KB
demoFruit_web.html 2KB
demoFruit_web.html 2KB
demoStu_annotation.html 2KB
demoStu_annotation.html 2KB
demo06.html 2KB
demo06.html 2KB
demo10.html 1KB
demo10.html 1KB
demoInfo.html 1KB
demoInfo.html 1KB
demoFruit.html 1KB
demoFruit.html 1KB
demoFruit.html 1KB
demoFruit.html 1KB
demo09.html 1KB
demo08.html 1KB
demo07.html 1KB
demo08.html 1KB
demo09.html 1KB
demo07.html 1KB
demo05.html 1KB
demo05.html 1KB
demo04.html 1KB
demo04.html 1KB
addFruit_annotation.html 679B
addFruit_annotation.html 679B
addFruit_web.html 672B
addFruit_web.html 672B
add.html 671B
add.html 671B
studentScore.html 633B
studentInfo.html 633B
studentScore.html 633B
studentInfo.html 633B
hello.html 435B
hello.html 435B
bottom.html 11B
bottom.html 11B
left.html 9B
main.html 9B
left.html 9B
main.html 9B
top.html 8B
top.html 8B
demo.iml 988B
thymeleaf-3.0.12.RELEASE.jar 845KB
thymeleaf-3.0.12.RELEASE.jar 845KB
javassist-3.20.0-GA.jar 733KB
javassist-3.20.0-GA.jar 733KB
共 153 条
- 1
- 2
资源评论
楼高日近
- 粉丝: 43
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功