session.setAttribute("session-name","value"); // Create Session session.getAttribute("session-name")// Get Session session.removeAttribute("session-name")// Delete Session
<html> <head> <title>ThaiCreate.Com JSP Tutorial</title> </head> <body> <% String strUser = "win"; String strName = "Weerachai Nukitram"; session.setAttribute("sUser",strUser); session.setAttribute("sName",strName); %> Session Created.<br><br> <a href="view.jsp">View session</a> </body> </html>
<html> <head> <title>ThaiCreate.Com JSP Tutorial</title> </head> <body> <u>View Session.</u><br> <% String strUser = String.valueOf(session.getAttribute("sUser")); String strName = String.valueOf(session.getAttribute("sName")); out.print("User : " + strUser); out.print("<br>"); out.print("Name : " + strName); %> <br><br> <a href="delete.jsp">Delete session</a> </body> </html>
<html> <head> <title>ThaiCreate.Com JSP Tutorial</title> </head> <body> <% session.removeAttribute("sUser"); session.removeAttribute("sName"); %> Session Deleted.<br><br> <a href="view.jsp">View session</a> </body> </html>
ช่วยกันสนับสนุนรักษาเว็บไซต์ความรู้แห่งนี้ไว้ด้วยการสนับสนุน Source Code 2.0 ของทีมงานไทยครีเอท