这是一个页面的一验证用户是否登录并确定是否转到登录界面。
采用的技术为struts2.0,没有使用sevlet。
<%String username =(String) request.getParameter("username");%>
<s:if test="#username == null">
<script>
if(confirm("请先登录!"))
window.location.href='<%=request.getContextPath()%>/Login.jsp';</script>
</s:if>
<div align="center">
<p>
欢迎用户:${sessionScope.username}
</p>
</div>
这段代码里首先使用request.getParameter来得到存入在session里的用户名,如果此用户没有登录,则得到的用户名为空。然后调用js代码,弹出确认框,确认后跳转到登录页面。
而${sessionScope.username则仅是为了展示另一种取得存入session里的信息的方式。