<div class="right usercont"> <span id="showUserSpan"><font color="#FFFFFF" > NO:<%=session.getAttribute("username") %> <%if(uname!=null){%><%=session.getAttribute("username") %>, <%}else{%>请登录 <%} %></font> </span> <p class="name fontyh">MR.ROWE</p>
今天明白了在html页面无法获取session,只有在jsp页面才能。
还有救是在Html页面无法获取尖括号。
<%=session.getAttribute("username") %>
在jsp页面的一些常识操作,我给一个session做为全局变量:
<%@ page language="java" contentType="text/html; charset=utf-8" 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></title> <link rel="stylesheet" type="text/css" href="common/website.css" /> <script type="text/javascript" src="script/jquery.js"></script> </head> <% String uname=(String)session.getAttribute("username"); %> <script type="text/javascript">//启动区 //登出操作
下面运用:
<div class="right usercont"> <span id="showUserSpan"><font color="#FFFFFF" > NO:<%=session.getAttribute("username") %> <%if(uname!=null){%><%=session.getAttribute("username") %>, <%}else{%>请登录 <%} %></font> </span> <p class="name fontyh">MR.ROWE</p>