• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2215
  • Last Modified:

check session

I have a file named index.jsp

<jsp:include page="inc_header.jsp" flush="true" />
<jsp:include page="inc_leftmenu.jsp" flush="true" />
<table width="100%"  border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td><br>
                  <fieldset>
                          <legend><strong>Trang qu&#7843;n l&yacute; website </strong></legend>
                  <table width="700"  border="0" align="center" cellpadding="10" cellspacing="10">
              <tr align="center">
                <td><a href="danhsachbrand.jsp"><img src="images/icon9.jpg" width="53" height="53" border="0"><br>
                  BEAUTY BRAND</a></td>
....
<jsp:include page="inc_footer.jsp" flush="true" />


And I have following code to check session

<%@ page language = "java" import = "Escentual.MemberAdmin.MemberAdmin, Escentual.Account.DBAccount, Escentual.Account.Account, java.sql.*, javax.servlet.http.*, javax.servlet.*, Escentual.Database.DBConnect" %>
<%
      MemberAdmin memberAdmin = new MemberAdmin();
      HttpSession httpSession = request.getSession(true);
      memberAdmin.setSession(httpSession);
      if (memberAdmin.returnUsernameSession() == null)
      {
            response.sendRedirect("login.jsp");
      }
%>

When I put it in "inc_header.jsp" , it didn't redirect to "login.jsp" . But when I put it in "index.jsp" , it worked correctly . Why ?
0
tunhien
Asked:
tunhien
  • 2
3 Solutions
 
suprapto45Commented:
Hi,

Is there any exception in your console? It could be that your response has been commited

David
0
 
suprapto45Commented:
Or...

Try to use RequestDispatcher

<%
     MemberAdmin memberAdmin = new MemberAdmin();
     HttpSession httpSession = request.getSession(true);
     memberAdmin.setSession(httpSession);
     if (memberAdmin.returnUsernameSession() == null)
     {
          String url="/login.jsp";
          RequestDispatcher rd = request.getRequestDispatcher(url);
          rd.forward(request, response);
          //response.sendRedirect("login.jsp");
     }
%>

David
0
 
Siva Prasanna KumarPrincipal Solutions ArchitectCommented:
<jsp:include page="inc_header.jsp" flush="true" />
<jsp:include page="inc_leftmenu.jsp" flush="true" />

just try removing flush = "true" in the above statements & try this.

<jsp:include page="inc_header.jsp" />
<jsp:include page="inc_leftmenu.jsp" />
0
 
aaaaaaCommented:
<%@ page language = "java" import = "Escentual.MemberAdmin.MemberAdmin, Escentual.Account.DBAccount, Escentual.Account.Account, java.sql.*, javax.servlet.http.*, javax.servlet.*, Escentual.Database.DBConnect" %>
<%
     MemberAdmin memberAdmin = new MemberAdmin();
     HttpSession httpSession = request.getSession(true);
     memberAdmin.setSession(httpSession);
     if (memberAdmin.returnUsernameSession() == null)
     {
         %><script>
              top.location.href='login.jsp'  
              </script>
          <%
     }
%>
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now