jsp頁面程式碼,獲取name為"name","password"的cookie,並把其值賦給變數

<%
  String name="";
  String psw="";
  String checked="";
  Cookie[] cookies=request.getCookies();
  if(cookies!=null && cookies.length!=0){
	  for(int i=0;i<cookies.length;i++){
		  Cookie cookie = cookies[i];
		  if(cookie.getName().equals("name")){
			  name = cookie.getValue();
			  checked="checked";
		  }
		  if(cookie.getName().equals("psw")){
			  psw = cookie.getValue();
		  }
	  }
		  
  }
%>


顯示變數的值

使用者名稱:

<input name="name" type="text" value="<%= name %>" id="name"/>


密碼:

<input name="password" type="password" value="<%= psw %>" id="password">


checked,是否記住密碼

<input name="rememberMe" type="checkbox" id="rememberMe" value="yes" class="checkbox" <%=checked %>>