cookie問題
在user.jsp中有如下代碼:
request.setCharacterEncoding("utf-8");
? ? ? ? String username ="";
? ? ? ? String password ="";
? ? ? ? Cookie[] cookies = request.getCookies();
? ? ? ? if(cookies!=null&&cookies.length>0)
? ? ? ? {
? ? ? ? ? ? for(Cookie c:cookies)
? ? ? ? ? ? {
? ? ? ? if(c.getName().equals("username"))
? ? ? ? {
? ? ? ? ? username = URLDecoder.decode(c.getValue(),"utf-8"); ? ? ?
? ? ? ? }
? ? ? ? if(c.getName().equals("password"))
? ? ? ? {
? ? ? ? ? password = URLDecoder.decode(c.getValue(),"utf-8"); ? ? ?
? ? ? ? }
? ? ? ? }
? ? ? ? ?}
? ? ? ? else{}
我不知道username和password是哪里來的!上個頁面也沒有傳過來???我們怎么知道username和password是一個鐵定的值,困惑中
2015-06-25
這段代碼的功能是從cookie取用戶名和密碼,先判斷cookie是不是有值,有了就拿,沒了就什么都不做。