1. 程式人生 > >js應用獲取session

js應用獲取session

1.後臺建立session

List<Map<String, Object>> list=loginSubmitService.loginSubmit(map);
		
		if(list!=null){
			HttpSession session =request.getSession();
			session.setAttribute("session", list);
		}

2.jsp js呼叫session

var us='<%=session.getAttribute("session")%>';
    	var account='<%=((List<Map<String,Object>>)session.getAttribute("session")).get(0).get("account")%>'; 
    	var password='<%=((List<Map<String,Object>>)session.getAttribute("session")).get(0).get("password")%>'; 

注意:jsp需要導包

<%@ page import="java.util.*" %>