title: How to redirect in JAX-RS after a post to a get
body: <p>I'm developing a simple login form (security is not a problem) where the user visits the page <code>login</code> inserts <em>username</em> and <em>password</em> and press <em>send</em> that POST these information to the page <code>check</code>.</p>
  
  <p>Page <code>check</code> checks credential and, if everything is OK, creates cookie and redirect to page <code>home</code>, otherwise redirects to page <code>login</code>.</p>
  
  <p>I use the following redirect:</p>
  
  <pre><code>return Response.temporaryRedirect(new URI("/home")).cookie(cookie, cookie2).build();
  </code></pre>
  
  <p>This redirects from <code>check</code> (@POST method) to <code>home</code> (@POST method), I just wanna to redirect to <code>home</code> (@GET method).</p>
  
  <p><strong>Important note</strong>: I'm a newbie of JAX and what I would like to create is a RESTful service. Are redirects a correct way to implement a REST service?</p>
  
  <p>Now I'll show you small slices of code hoping:</p>
  
  <p><code>check</code> Page</p>
  
  <pre><code>@POST
  @Produces(MediaType.TEXT_HTML)
  public Response checkLogin(@FormParam(Login.fieldUsername) String user, @FormParam(Login.fieldPsw) String psw) throws URISyntaxException {
      boolean val = db.checkLogin(user, psw);
      NewCookie cookie;
      NewCookie cookie2;
      if(val){
          //Valid access + cookie creation
          cookie = new NewCookie("username", user);
          cookie2 = new NewCookie("hashedPassword", psw);
          return Response.temporaryRedirect(new URI("/home")).cookie(cookie, cookie2).build();
      } else {
          //Wrong login + cookie deletion
          cookie = new NewCookie("username", "");
          cookie2 = new NewCookie("hashedPassword", "");
          return Response.temporaryRedirect(new URI("/login")).cookie(cookie, cookie2).build();
      }
  }
  </code></pre>
  
  <p><code>login</code> page</p>
  
  <pre><code>@GET
  @Produces(MediaType.TEXT_HTML)
  public Response showLoginForm() throws URISyntaxException{
      boolean validCookie = db.checkLogin(username, hashedPassword);
  
      String data = "&lt;form name='Username' action='"+ redirect +"' method='post'&gt;&lt;ul&gt;"
              + "&lt;li&gt;&lt;label for='"+fieldUsername+"'&gt;Username&lt;/label&gt;"
              +   "   &lt;input type='text' name='"+fieldUsername+"' placeholder='Insert username' required&gt;&lt;/li&gt;"
              + "&lt;li&gt;&lt;label for='"+fieldPsw+"'&gt;Password&lt;/label&gt;"
              +   "   &lt;input type='password' name='"+fieldPsw+"' placeholder='Insert password' required&gt;&lt;/li&gt;"
              + "&lt;li&gt;&lt;input type='submit' value='Login'&gt;"
              + "&lt;/li&gt;&lt;/ul&gt;&lt;/form&gt;";
      if(validCookie){
          return Response.temporaryRedirect(new URI(homepage)).build();
      }
      else {
          return Response.ok( showTheForm(data) ).build();
      }
  }
  </code></pre>