title: php's Header equivalent in JSP
body: <p>in php i used to authenticate whether a user was logged in or not by checking the session for a member id, if set ok, else the page would be redirected via Header to the login page. this auth script was in auth.php and i used to include it in any page that required login. simple. however i cannot do the same in jsp. because the rest of the page which includes the auth.jsp gets loaded no matter what auth.jsp does. the auth.jsp is</p>
  
  <pre><code>&lt;%
  UserService userService = UserServiceFactory.getUserService();
  User user = userService.getCurrentUser();
  if (user == null) {
  %&gt;
  &lt;jsp:forward page="/index"/&gt;
  &lt;%
  return; 
  }
  %&gt;
  </code></pre>
  
  <p>if the user is not logged in he still can see the original page below the login page. because of this i have to manually include the user checking using if else on every page, very inconvenient. any solutions??
  the including page is</p>
  
  <pre><code>&lt;jsp:include page="auth.jsp" /&gt;
  &lt;p&gt;Welcome&lt;/p&gt;
  </code></pre>