JSP页面获取不到Servlet传过来的session....求解,附代码如下:
servlet中:HttpSessionsession=request.getSession();//session.setAttribute("role",role);...
servlet中:
HttpSession session=request.getSession();
//session.setAttribute("role", role);
DataLogin dl=new DataLogin();
boolean flag=dl.loginJudge(role, name, password);
if(flag){
session.setAttribute("loginName", name);
session.setAttribute("role", kind);
//out.print(name);
if(kind.equals("student")){
out.print("<script>location.href='../student.jsp'</script>");
}
if(kind.equals("teacher")){
out.print("<script>location.href='../teacher.jsp'</script>");
}
if(kind.equals("admin")){
out.print("<script>location.href='../admin.jsp'</script>");
}
}else {
out.print("<script>location.href='../index.jsp';alert('该用户不存在')</script>");
}
jsp中:
<%
String loginname =(String) session.getAttribute("loginname");
if(loginname == null ){
%>
<script type="text/javascript">
location.href="index.jsp";
</script>
<%
}
%>
结果是:返回到index.jsp
admin.jsp中 loginname 值为null.......................... 展开
HttpSession session=request.getSession();
//session.setAttribute("role", role);
DataLogin dl=new DataLogin();
boolean flag=dl.loginJudge(role, name, password);
if(flag){
session.setAttribute("loginName", name);
session.setAttribute("role", kind);
//out.print(name);
if(kind.equals("student")){
out.print("<script>location.href='../student.jsp'</script>");
}
if(kind.equals("teacher")){
out.print("<script>location.href='../teacher.jsp'</script>");
}
if(kind.equals("admin")){
out.print("<script>location.href='../admin.jsp'</script>");
}
}else {
out.print("<script>location.href='../index.jsp';alert('该用户不存在')</script>");
}
jsp中:
<%
String loginname =(String) session.getAttribute("loginname");
if(loginname == null ){
%>
<script type="text/javascript">
location.href="index.jsp";
</script>
<%
}
%>
结果是:返回到index.jsp
admin.jsp中 loginname 值为null.......................... 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询