1. 쿠키
1. 쿠키 설정, 내용은 시간입니다
쿠키 쿠키 = 새 쿠키 ( "lastAccessTime", System.CurrentTimeMillis ()+""); Cookie.SetMaxage (1*30*24*3600); // 1 개월의 유효 기간 설정 쿠키 .setPath ( "/Project Name"); // 전체 프로젝트에 액세스 할 때 제공됩니다.
2. 쿠키 정보를 얻으십시오
쿠키 쿠키 [] = request.getCookies (); for (int i = 0; cookie! = null && i <cookies.length; i ++) {if (쿠키 [i] .getName (). equals ( "lastAccestTime")) {long cookievalues = long.parselong (쿠키 [i]. getVlues ()); // 십두 날짜로 문자열을 변환합니다 (새 날짜); response.getwrite (). print (date); }}2. 세션 (getsession ()-> 세션이 30 분 동안 사용되지 않음)
1. 세션 설정
httpsession session = request.getSession (); session.setAttribute ( "name", "hahahahahaha");
2. 세션을 얻으십시오
httpsession session = request.getsession (); // httpsession session = request.getSession (false); // string str = (string) session.getAttribute ( "name")를 생성하지 않고 만 가져옵니다.
3. 세션 구성, 구성 시간
<Seeion-Config> <Session-TimeOut> 20 </session-timeout> </session-config>
4. 세션 파괴
httpsession session = request.getsession (); session.invalidate (); // session.removeattribute ( "xxx"); // removeattribute ( "xxx"); // 세션을 제거합니다
5. 주소를 다시 작성하여 세션을 얻으려면 쿠키가 비활성화 된 경우에만 다시 작성됩니다.
request.getSession (); String url1 = response.encodingUrl ( "다시 작성 해야하는 주소 1"; String url2 = response.encodingUrl ( "다시 작성 해야하는 주소 2"); printwriter out = response.getWriter; out.print ( "<a href = '"+url1+"'xxxx </aprine"; ' "+url2+"'> yyyy </a> ");
3. 클라이언트 양식 제출 문제
1. 빈 암호 제출을 방지합니다
<form action = "/project/xxx"method = "post"onsubmit = "return dosubmit (this)"> username : <input type = "text"name = "username"> <br/> password : <입력 유형 = "암호"이름 = "password"> <br/ <br/ <br/ <br/ <br/ <br/ <br/ <brs "> </form> <script> 함수 doSubment. if (obj.category.value == '') {Alter ( "Please Enter"); 거짓을 반환합니다. }} </script>2. 반복 제출을 방지합니다
<form action = "/project/xxx"method = "post"onsubmit = "return dosubmit ()"> username : <input type = "text"name = "username"> <br/> password : <입력 유형 = "password"name = "password"> <br/> <input type = "value ="</form> <script> 함수 dosubment; if (! iscommitted) {iscommitted = true; 진실을 반환하십시오. } else {return false; }} </script>요약
위의 것은 서블릿 세션 기술의 기본 분석에 대한이 기사의 모든 내용이며, 모든 사람에게 도움이되기를 바랍니다. 관심있는 친구는이 사이트의 다른 관련 주제를 계속 참조 할 수 있습니다. 단점이 있으면 메시지를 남겨 두십시오. 이 사이트를 지원해 주신 친구들에게 감사드립니다!