title: response.sendRedirect in JSP
body: <p>This is my current JSP code:</p>
  
  <pre><code>&lt;%@ page language="java" contentType="text/html; charset=UTF-8"
  pageEncoding="UTF-8"%&gt;
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"     "http://www.w3.org/TR/html4/loose.dtd"&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt;
  &lt;title&gt;Insert title here&lt;/title&gt;
  &lt;/head&gt;
  
  
  &lt;jsp:useBean id="user" class= "uts.wsd.User" scope="session" &gt;&lt;/jsp:useBean&gt;
  
  
  &lt;% 
  String name = request.getParameter("name");
  String email = request.getParameter("email");
  String password = request.getParameter("password");
  String gender = request.getParameter("gender");
  String color = request.getParameter("favcol");
  
  user.setName(name);
  user.setEmail(email);
  user.setPassword(password);
  user.setGender(gender);
  user.setFavouriteColour(color);
  %&gt;
  &lt;body style="background: &lt;%= color %&gt;;"&gt;
  
  &lt;% if (request.getParameter("tos") == null ) {%&gt;
  &lt;p&gt;
  Sorry, you must agree to the Terms of Service.&lt;/p&gt;
  &lt;p&gt;Click &lt;a href="register.jsp" &gt; here &lt;/a&gt; to go back.
  &lt;/p&gt;
  
  &lt;%}  else { %&gt;
      &lt;jsp:forward page="index.jsp" /&gt;
  &lt;% } %&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Here I use <code>jsp:forward page="index.jsp"</code> to redirect to index.jsp page. Then, if I want to use <code>response.sendRedirect("index.jsp")</code>? How can I proceed? </p>
  
  <p>I tried this:</p>
  
  <pre><code>&lt;% if (request.getParameter("tos") == null ) {%&gt;
  &lt;p&gt;
  Sorry, you must agree to the Terms of Service.&lt;/p&gt;
  &lt;p&gt;Click &lt;a href="register.jsp" &gt; here &lt;/a&gt; to go back.
  &lt;/p&gt;
  
  &lt;%}  else { %&gt;
      &lt;response.sendRedirect("index.jsp")&gt;
  &lt;% } %&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>But it failed. Please help! Thank you!!</p>