title: forwarding with RequestDispatcher after going through Java Filter
body: <p>First of all let me describe what I'm trying to do, which I'm guessing is pretty simple.
  I have a website with users and want to restrict access to a view_profile.jsp page only to logged users. I have a filter mapped to:</p>
  
  <pre><code>&lt;url-pattern&gt;/auth/*&lt;/url-pattern&gt;
  </code></pre>
  
  <p>which looks like this</p>
  
  <pre><code>        try {
          HttpSession session = ((HttpServletRequest)request).getSession();
          UserBean user = (UserBean)session.getAttribute("currentUser");
          if (user != null &amp;&amp; user.isValid()){
              System.out.println("Filter: context -&gt; " + ((HttpServletRequest)request).getContextPath()); //returns ""
              chain.doFilter(request, response);
          }
          else{
              ((HttpServletResponse)response).sendRedirect("/login.jsp"); //works fine
          }
  </code></pre>
  
  <p>This filter is run when on the index.jsp page user will click on a link:</p>
  
  <pre><code>&lt;a href="./auth/view_profile?profile=${sessionScope.currentUser.username}"&gt;
  //yeah, he will 'view' himself - it's just an example
  </code></pre>
  
  <p>which is suppose to take the user to the servlet mapped to ViewProfileServlet mapped to:</p>
  
  <pre><code>&lt;url-pattern&gt;/auth/view_profile&lt;/url-pattern&gt;
  </code></pre>
  
  <p>which looks like that:</p>
  
  <pre><code>    try {
          String username = (String) request.getParameter("profile");
  
          // here is getting info from database and setting request attributes
          // works fine
  
                  //response.sendRedirect("/view_profile.jsp");
                  System.out.println("ViewProfileServlet: In context -&gt; " + getServletContext().getContextPath()); // returns ""
                  dis = getServletContext().getRequestDispatcher("/view_profile.jsp");
                  // i've tried request.getRequestDispatcher. no difference
                  System.out.println("ViewProfileServlet: forward to '/view_profile.jsp'");
                  dis.forward(request, response);
              }
  </code></pre>
  
  <p>Which in turn should take the user to the /view_profile.jsp (in the root context, not in /auth) and work, which it doesn't. What happens is the ViewProfileServlet runs and the view_profile.jsp shows, although it seems that the context is still /auth because all the links on view_profile.jsp point to i.e localhost:8080/auth/some-page.jsp. Also, css files are not being loaded, they're not even requested (at least according to firebug), and page source shows 404 Glassfish Error where css's suppose to be. </p>
  
  <p>I would greatly appreciate any help, it's the first time i'm even doing something in jsp and i'm completely lost here.</p>