響應行:響應的協議 響應的狀態碼 響應的描述java
響應頭瀏覽器
響應正文服務器
注意:設置錯誤的要用:sendError()post
public static void main(String[] args) throws Exception { String str = "帶門"; byte[] b = str.getBytes("utf-8");//模擬瀏覽器進行編碼 String name = new String(b,"iso-8859-1");//模擬服務器進行解碼 // byte[] by = name.getBytes("iso-8859-1");//反服務器進行編碼 // String str1 = new String(by,"utf-8"); String str1 = new String(name.getBytes("iso-8859-1"),"utf-8"); System.out.println(str1); }
String name = request.getParameter("username");//根據用戶的name的屬性值獲得相應的提交信息 String name1 = new String(name.getBytes("iso-8859-1"),"utf8"); System.out.println(name1);
request.getRequestDispatcher("/servlet6").forward(request, response); //地址沒變,網頁中顯示的內容是sevlet6的內容編碼
request.getRequestDispatcher("/servlet6").include(request, response); //地址沒變,網頁中顯示的是原來servlet中的內容和servlet6的內容。spa
request.getAttribute("鍵");code
request.setAttribute("鍵","值");生命週期
request.removeAttribute("鍵");utf-8
request.getAttributeNames();rem
ServletContext (域) :同生共死
Servlet :聲明週期 :不求同生,只求同死。
request:完整的一次請求響應。