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 ?
tunhienAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

suprapto45Commented:
Hi,

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

David
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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" />
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>
          <%
     }
%>
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JSP

From novice to tech pro — start learning today.