這裏寫目錄標題
1、基本概念
1.1、get、post
格式
get和post的區別
2、內置對象
2.1、九大內置對象
2.2、解決頁面中出現的中文亂碼
idea默認utf-8,但是eclipse編碼需要改變編碼方式
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("utf-8");
<%@ page language="java"contentType="text/html";charset=utf-8"%>
//注意統一編碼
request.setCharacterEncoding("utf-8");
//響應編碼設置
response.setContentType("text/html; charset=UTF-8");
response.setCharacterEncoding("utf-8");
如果get請求出現亂碼
//治標的方法:
new String(s.getBytes(“iso-8859-1”),”utf-8”);
//治本的辦法:配置tomcat\conf\server..xml文件,修改爲URIEncoding=”utf-8”,useBodyEncodingForURI=”ture”
2.3、在請求中保存和獲取屬性
2.4、轉發和重定向
2.5、request、response
2.6、session
一個會話就是在瀏覽器和服務器之間的一次通話,如果接通就會一直在會話,直到掛斷
會話可以在多次請求中保存和使用數據
每個session都有唯一的id,這個id可以直接打印出來
Session.invalidate();//讓session失效
Session.removeAttribute(“userName”);//移除session中指定的數據
Session.setMaxInactiveInterval(5);//設置session的生命週期
這裏的config是在web.xml文件裏修改
整個session的過程如下
2.7、cookie
使用cookie自動填充用戶名
步驟
1、將用戶名保存到cookie
Cookie cookie=new Cookie(“userName”,usernName);
2、
Response.addCookie(cookie);
2.8、application
<%\
Int count=1;
Object count1=application.getAttribute(“count”);
If(count1!=null){
Count=count+Integer.ParseInt(count1.toString());
}
%>
<h3>
<%=count%>
</h3>