1. 程式人生 > >session存取

session存取

get prefix set 登錄名 user width lis jsp msg

HttpSession session = request.getSession();

User loginUser = this.service.loginUser(list); User是個對象

session.setAttribute("user", loginUser);

在此存入:session.setAttribute("msg", "用戶或密碼錯誤!");

在jsp頁面裏的js語言裏讀取和移除

<script type="text/javascript">

var msg = "${sessionScope.msg}";
if(msg!=null && msg!=""){
alert(msg);
}
<%request.getSession().removeAttribute("msg");%>

</script>

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>

<TR> <th width="20%" align="center">用戶登錄名</th>
<TD class="BGCgray">${sessionScope.user.ur_loginName }</TD>
</TR>

session存取