title: Passing parameters in a response.sendRedirect() - JSP
body: <p>I am new to Web Technologies. I am trying to do a simple program which ask the user to input a name, if valid the page redirects to another jsp file <code>"RedirectIfSuccessful.jsp"</code>, if invalid the page redirects to <code>"RedirectIfFailed.jsp"</code>. I am using the <code>response.sendRedirect()</code> method to do this.</p>
  
  <p>The redirect is working fine. However, I wish to access the name the user inputs in the form from <code>RedirectIfSuccessful</code> and <code>RedirectIfFailed</code> files so that when a valid name is entered the user is presented with a : Welcome, nameEntered and when failed the message would be nameEntered was not valid. Please go back and try again.</p>
  
  <p>I tried using <code>request.getParameter("name")</code> from  both files but it's returning a <code>null</code> value.. What can I do to access it?</p>
  
  <p>This is the code I have: This is the <code>RedirectingPage.jsp</code></p>
  
  <pre><code> &lt;%@ page 
      language="java" 
      import="java.util.regex.*"
      contentType="text/html; charset=ISO-8859-1"
      pageEncoding="ISO-8859-1"%&gt;
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt;
  
  
  &lt;%  
      String name = request.getParameter("name");
  
      final String NAME_PATTERN = "^[a-zA-Z]{3,15}$";
      Pattern pattern = Pattern.compile(NAME_PATTERN);
  
      Matcher matcher = pattern.matcher(name);
  
      if (matcher.matches() == true){
          response.sendRedirect("RedirectIfSuccessful.jsp");
  
      } else {
          response.sendRedirect("RedirectIfFailed.jsp");
      }
  
  %&gt;
  </code></pre>
  
  <p>This is the HTML file where I have the form: <code>FormSubmit.html</code></p>
  
  <pre><code>&lt;html&gt;
      &lt;head&gt;
          &lt;title&gt; Welcome &lt;/title&gt;
      &lt;/head&gt;
  
      &lt;body BGCOLOR="#FDF5E6"&gt;
          &lt;p&gt; &lt;i&gt; This program redirects to a page if the name entered is valid and to another one if name
              entered is invalid... This uses response.sendRedirect() &lt;/i&gt; &lt;/p&gt;
  
          &lt;form action="RedirectingPage.jsp" method="post"&gt;
            &lt;font size=6 face="Georgia"&gt; &lt;strong&gt; Enter your name: &lt;/strong&gt; &lt;/font&gt; &lt;input type="text" name="name"&gt; &lt;br&gt; &lt;br&gt;
            &lt;input type="submit" name="btn" value="Submit" &gt;
          &lt;/form&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>And this is the Successful page:</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"&gt;
  &lt;title&gt; Successful Submit &lt;/title&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
  
  &lt;font face="Georgia" size="6"&gt; Hello, &lt;% request.getParameter("name"); %&gt; &lt;/font&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>I hope you can help and I was clear in my question. Thanks :)</p>