parangjiwa_1 1 Report post Posted July 13, 2009 Salam...hamba nak bertanya..kalau silap umah..sorry ekk..hamba wat satu login/logout simple nag JSP guna session...mmg jadi..tetapi setelah logout, masih bleh masuk ke page sebelumnya bila kita click "back" kat browser..camner ek...ahmab dh try solution2 dari pakcik Google dan Yahoo..tp still tak dpt...code2 hamba sprti di bawah:sessionForm.jspCode:<%@page contentType="text/html" pageEncoding="UTF-8"%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><% String usernameFinal=(String) session.getAttribute("usernameSession"); if(usernameFinal==null) { out.println("you are log out!!Session id is: "+session.getId()); } else { out.println("you are still logged in.."+session.getId()); }%><html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>JSP Page</title></head><body><form method="post" action="setSession.jsp">Enter your name: <input type="text" name="userName"><input type="submit" value="Submit"></form></body></html>setSession.jspCode:<%response.setHeader("Cache-Control","no-cache"); //Forces caches to obtain a new copy of the page from the origin serverresponse.setHeader("Cache-Control","no-store"); //Directs caches not to store the page under any circumstanceresponse.setDateHeader("Expires", 0); //Causes the proxy cache to see the page as "stale"response.setHeader("Pragma","no-cache"); //HTTP 1.0 backward compatibility%><%@page contentType="text/html" pageEncoding="UTF-8"%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>JSP Page</title></head><%String usernameInput=request.getParameter("userName"); // get userName value from form and store in variable... out.println(usernameInput);if((usernameInput==null)||(usernameInput=="")) { //out.println("Name required!"); %><jsp:forward page="sessionForm.jsp"/><% }else { out.println("Session available but not yet set..Now setting session attributes"); }session.setAttribute("usernameSession", usernameInput); //create the session object with the name usernameSession out.println("ok...done setting the session...the session id is still da same: "+session.getId());%><body><p><a href="showSessionValue.jsp">Next to show session values</a><p></body></html>showSessionValue.jspCode:<%response.setHeader("Cache-Control","no-cache"); //Forces caches to obtain a new copy of the page from the origin serverresponse.setHeader("Cache-Control","no-store"); //Directs caches not to store the page under any circumstanceresponse.setDateHeader("Expires", 0); //Causes the proxy cache to see the page as "stale"response.setHeader("Pragma","no-cache"); //HTTP 1.0 backward compatibility%><%@page contentType="text/html" pageEncoding="UTF-8"%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><%String usernameFinalZ=(String) session.getAttribute("usernameSession");request.getSession();out.println(usernameFinalZ);if(usernameFinalZ==null)//if(request.getAttribute("usernameSession")==null) { %><jsp:forward page="home.jsp"/><% }else { out.println("HOI! Session still set. the session id is: "+session.getId()); }%><html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>JSP Page</title></head><body><input type="hidden" id="refreshed" value="no"><%String usernameFinal=(String) session.getAttribute("usernameSession");//if(usernameFinal==null)//{//usernameFinal="";//}%> <p>Welcome: <%=usernameFinal%></p> <p>Session id is: <%=session.getId()%></p> <a href="sessionLogout.jsp">Logout</a></body></html>sessionLogout.jspCode:<%@page contentType="text/html" pageEncoding="UTF-8"%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>JSP Page</title></head><body><% //String usernameFinal=(String) session.getAttribute("usernameSession"); //ada 2 cara untuk logout!cara 1 dan cara 2. tp cara 1 lebih clear dan specific! //cara1 //session.removeAttribute("usernameSession"); //%><jsp:forward page="home.jsp"/><% //cara2 session.invalidate(); %><jsp:forward page="home.jsp"/> </body></html>ok..harap dapat bantu..trimas y'all. Quote Share this post Link to post Share on other sites
parangjiwa_1 1 Report post Posted August 14, 2009 ok..since takder reply. Topik ditutup. SEKIAN!!! Quote Share this post Link to post Share on other sites