title: request.getRequestDispatcher("URL").forward(request,response) Not Working
body: <p>I am trying to redirect to a jsp when an input validation error is found in case of data tampering. When I change the value for one of the fields it works properly but when value is changed for variable metricId[i] to "" it executes the code for request.getRequestDispatcher line but doesn't redirect it to the required page. Please help.</p>
  
  <p>The code is as given below:</p>
  
  <pre><code>    public void validateGenerateCustomReportCommand(HttpServletRequest request,
          HttpServletResponse response,
          CustomReportCommand customReportCommand) {
      try {
          boolean invalidInputFound = false;
          System.out.println("Inside validateGenerateCustomReportCommand");
          String[] metricIds = customReportCommand.getMetricIds();
  
          String[] attrIdValueId = customReportCommand.getAttrValueIds();
  
          for (int i = 0; i &lt; attrIdValueId.length; i++) {
              if (!(regexMatcher.validateSearch(attrIdValueId[i]))) {
                  invalidInputFound = true;
                  logger.error("Invalid input for Attribute Set");
              }
          }
  
          for (int i = 0; i &lt; metricIds.length; i++) {
  
              if(metricIds[i] == null){
                  invalidInputFound = true;
              }
  
              if(metricIds[i] == ""){
                  request.getRequestDispatcher("/pages/moncoeError.jsp").forward(
                          request, response);
              }
  
              if (!(regexMatcher.validateMetricId(metricIds[i]))) {
                  invalidInputFound = true;
              }
  
          }
  
          if (customReportCommand.getUnitValue() != null
                  &amp;&amp; customReportCommand.getUnitValue() != "") {
              Long unitValue = Long.parseLong(customReportCommand
                      .getUnitValue());
              if (unitValue &lt; 1 || unitValue &gt; 365) {
                  invalidInputFound = true;
              }
          } 
  
          if (customReportCommand.getFromDate() != null
                  &amp;&amp; customReportCommand.getToDate() != null
                  &amp;&amp; customReportCommand.getFromDate() != ""
                  &amp;&amp; customReportCommand.getToDate() != "") {
  
              if (!(regexMatcher.validateDate(customReportCommand
                      .getFromDate()) || (!(regexMatcher
                      .validateDate(customReportCommand.getToDate()))))) {
                  invalidInputFound = true;
              }
  
          }
  
          if(customReportCommand.getUnit() != "Days"){
              invalidInputFound = true;
          }
  
          if(customReportCommand.getName()==null || customReportCommand.getName() == ""){
              invalidInputFound = true;
          }else if(customReportCommand.getName().length() &gt; 250){
              invalidInputFound = true;
  
          }
  
          if(customReportCommand.getDescription()==null || customReportCommand.getDescription() == ""){
              invalidInputFound = true;
          }else if(customReportCommand.getDescription().length() &gt; 500){
              invalidInputFound = true;
  
          }
  
  
  
  
  
          if (invalidInputFound) {
              System.out.println("Invalid input found");
              request.getRequestDispatcher("/pages/moncoeError.jsp").forward(
                      request, response);
          }
      } catch (Exception e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      }
  }
  </code></pre>