title: Redirection in a Liferay portlet using response.sendRedirect
body: <p>I am trying to port a mobile web application into liferay.  I have managed to port over most of the code, but the problem is that transistions keep going fullscreen.</p>
  
  <p>I have read various postings on using portlet:actionURL and this seems to resolve to a much longer user with other parameters on it, but it throws my browser in a loop with a blank screen.</p>
  
  <p>login.jsp</p>
  
  <pre><code>&lt;form id="loginForm" action="&lt;%= PortalUtil.getPathContext(request) + "/Submit" %&gt;" method="post" autocomplete="off"&gt;
      &lt;label for="userid"&gt;User Number&lt;/label&gt;
      &lt;input type="number" name="userid" id="userid" pattern="[0-9]*" value=""&gt;
  
      &lt;label for="userpass"&gt;Password&lt;/label&gt;
      &lt;input type="password" name="userpass" id="userpass" value=""&gt;
  
      &lt;button type="submit" name="submit" value="submit" data-theme="a"&gt;Submit&lt;/button&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>SubmitForm.java</p>
  
  <pre><code>package controller;
  
  import java.io.IOException;
  import javax.servlet.http.HttpServlet;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  import javax.servlet.http.HttpSession;
  import javax.servlet.ServletException;
  import javax.servlet.annotation.WebServlet;
  
  @WebServlet("/Submit")
  public class SubmitForm extends HttpServlet {
      public HttpSession getSession(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
          // Do required initialization
          HttpSession session = null;
          session = request.getSession(false);
          return session;
      }
  
      // POST Method, Servlet contains NO GET Method
      protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
          String action = "";
          try {
              HttpSession session = getSession(request, response);
              String user = session.getAttribute("user");
              session.setAttribute("user", user);
              session.setAttribute("redirect", "Home");
              //session.setAttribute("redirect", "Status");
              //session.setAttribute("redirect", "Login");
              //session.setAttribute("redirect", "Error");
              response.sendRedirect("redirect.jsp");
          } catch (ServletException e) {
              System.err.println("ServletException:", e);
          } catch (IOException e) {
              System.err.println("IOException:", e);
          }
          return;
      }
  }
  </code></pre>
  
  <p>redirect.jsp</p>
  
  <pre><code>&lt;%@page contentType="text/html" pageEncoding="UTF-8"%&gt;
  &lt;%
      String url = (String) session.getAttribute("redirect");
      System.out.println("redirect.jsp:url=" + url);
      if (null == url)
        url = "index.jsp";
      else
        session.removeAttribute("redirect");
  %&gt;
  &lt;!DOCTYPE html&gt;
  &lt;html&gt;
    &lt;head&gt;&lt;/head&gt;
    &lt;body&gt;
      &lt;script type="text/javascript"&gt;
        window.location.href = "&lt;%=url%&gt;";
      &lt;/script&gt;
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>web.xml</p>
  
  <pre><code>&lt;servlet&gt;
    &lt;servlet-name&gt;status-jsp&lt;/servlet-name&gt;
    &lt;jsp-file&gt;/status.jsp&lt;/jsp-file&gt;
  &lt;/servlet&gt;
  &lt;servlet-mapping&gt;&lt;servlet-name&gt;status-jsp&lt;/servlet-name&gt;&lt;url-pattern&gt;/Status&lt;/url-pattern&gt;&lt;/servlet-mapping&gt;
  &lt;servlet&gt;
    &lt;servlet-name&gt;home-jsp&lt;/servlet-name&gt;
    &lt;jsp-file&gt;/home.jsp&lt;/jsp-file&gt;
  &lt;/servlet&gt;
  &lt;servlet-mapping&gt;&lt;servlet-name&gt;home-jsp&lt;/servlet-name&gt;&lt;url-pattern&gt;/Home&lt;/url-pattern&gt;&lt;/servlet-mapping&gt;
  &lt;servlet&gt;
    &lt;servlet-name&gt;login-jsp&lt;/servlet-name&gt;
    &lt;jsp-file&gt;/login.jsp&lt;/jsp-file&gt;
  &lt;/servlet&gt;
  &lt;servlet-mapping&gt;&lt;servlet-name&gt;login-jsp&lt;/servlet-name&gt;&lt;url-pattern&gt;/Login&lt;/url-pattern&gt;&lt;/servlet-mapping&gt;
  &lt;servlet&gt;
    &lt;servlet-name&gt;error-jsp&lt;/servlet-name&gt;
    &lt;jsp-file&gt;/error.jsp&lt;/jsp-file&gt;
  &lt;/servlet&gt;
  &lt;servlet-mapping&gt;&lt;servlet-name&gt;error-jsp&lt;/servlet-name&gt;&lt;url-pattern&gt;/Error&lt;/url-pattern&gt;&lt;/servlet-mapping&gt;
  </code></pre>
  
  <p>new
  redirect.jsp</p>
  
  <pre><code>&lt;%@page contentType="text/html" pageEncoding="UTF-8"%&gt;
  &lt;%
      String url = (String) session.getAttribute("redirect");
      System.out.println("redirect.jsp:url=" + url);
      if (null == url) {
          url = "index.jsp";
      } else {
          session.removeAttribute("redirect");
      }
  %&gt;
  &lt;portlet:actionURL var="portleturl" &gt;
    &lt;portlet:param name="jspPage" value="/portlet/&lt;%=url%&gt;"/&gt;
  &lt;/portlet:actionURL&gt;
  &lt;!DOCTYPE html&gt;
  &lt;html&gt;
      &lt;head&gt;&lt;/head&gt;
      &lt;body&gt;
          &lt;script type="text/javascript"&gt;
              //window.location.href = "&lt;%=url%&gt;";
              console.log("${portleturl}");
              window.location.href = "${portleturl}";
          &lt;/script&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>