title: Redirecting my jsp form to success page
body: <p>i have a jsp registration form which on providing valid inputs and on successful validation should be directed to Success.jsp in WEB-INF/WebPages.Am passing this jsp to a servlet- service and DAO using a DTO and then the data will be inserted inside the database. But now after successful registration how to redirect it to the successPage. </p>
  
  <p>Following are my source codes:</p>
  
  <p><strong>AffiliateServlet</strong></p>
  
  <pre><code> Affiliate af= new Affiliate();
      af.setFisrtName(request.getParameter("txtFname"));
          af.setLastName(request.getParameter("txtLname"));
          af.setGender(request.getParameter("txtGender"));
          af.setCategory(request.getParameter("txtCategory"));
          String dob=(request.getParameter("txtDob"));
  
          try {
              SimpleDateFormat formatter=new SimpleDateFormat("MM/dd/yyyy");
              formatter.setLenient(false);
              Date date=formatter.parse(dob);
              af.setDate(date);
          } catch (ParseException e) {
             e.printStackTrace();
          }
  
          af.setAge(Integer.parseInt(request.getParameter("txtAge")));
          af.setAddress(request.getParameter("txtAddr"));
          af.setCountry("India");
          af.setState(request.getParameter("txtState"));
          af.setCity(request.getParameter("txtCity"));
          af.setPinCode(Integer.parseInt(request.getParameter("txtPin")));
          af.setEmailId(request.getParameter("txtEmail"));
          String std=request.getParameter("txtStd");
          int Std=Integer.parseInt(std);
          String con=request.getParameter("txtPhone");
          int contactNo=Integer.parseInt(con);
          af.setContactNo(Std+"-"+contactNo);
          String mob=request.getParameter("txtMobile");
          Long mobileNo=Long.parseLong(mob);
          af.setMobileNo("+91-"+mobileNo);
  
      AffiliateService afs=new AffiliateService();
      afs.createAffiliate(af);
  request.getRequestDispatcher("/WEB-INF/WebPages/success.jsp").forward(request, response);
      }
  
  }
  </code></pre>
  
  <p><strong>AffiliateService</strong></p>
  
  <pre><code>public class AffiliateService {
      Affiliate affiliate=null;
  
  
      public Affiliate createAffiliate( Affiliate affiliate) {
           validateAffiliate(affiliate);
          return affiliate;
              }
  
  
      private Affiliate validateAffiliate(Affiliate affiliate) {
          this.affiliate=affiliate;
           if(affiliate!=null){
         AffiliateDAO afd=new AffiliateDAO();
         DataSource dataSource=new DataSource();
         afd.setDataSource(dataSource);
          afd.insertAffiliate(affiliate);
      }
      return affiliate;
  
  }
  
  
  }
  </code></pre>
  
  <p><strong>AffiliateDAO</strong></p>
  
  <pre><code>public void insertAffiliate(Affiliate affiliate){
      String sql="INSERT INTO REGISTER " +"(id,FisrtName,LastName,Gender,Category,DateOfBirth,Age,Address,Country,State,City,PinCode,EmailId,ContactNo,MobileNo)VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
      Connection conn = null;
  
      try {
          conn = dataSource.createConnection();
          PreparedStatement ps = conn.prepareStatement(sql);
          ps.setInt(1, affiliate.getId());
          ps.setString(2, affiliate.getFisrtName());
          ps.setString(3, affiliate.getLastName());
          ps.setString(4,affiliate.getGender());
          ps.setString(5, affiliate.getCategory());
          ps.setDate(6, new java.sql.Date(affiliate.getDate().getTime()));
          ps.setInt(7, affiliate.getAge());
          ps.setString(8, affiliate.getAddress());
          ps.setString(9,affiliate.getCountry());
          ps.setString(10,affiliate.getState());
          ps.setString(11, affiliate.getCity());
          ps.setInt(12, affiliate.getPinCode());
          ps.setString(13, affiliate.getEmailId());
          ps.setString(14,affiliate.getContactNo());
          ps.setString(15, affiliate.getMobileNo());
  
          ps.executeUpdate();
          ps.close();
  
      } catch (SQLException e) {
          throw new RuntimeException(e);
  
      } finally {
          if (conn != null) {
              try {
                  conn.close();
              } catch (SQLException e) {}
          }
      }
  }
  </code></pre>
  
  <p><strong>I tried using RequestDispatcher in AffiliateServlet after afs.createAffiliate(af); but still unable to redirect</strong> </p>
  
  <p><strong>Please some one help me in this regard...</strong></p>