title: How to pass variable from java to jsp?
body: <p><strong>EmployeeController.java</strong>  </p>
  
  <pre><code>protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
              // TODO Auto-generated method stub
              Employee employee = new Employee();
              employee.setFirstname(request.getParameter("firstName"));
              employee.setLastname(request.getParameter("lastName"));
              employee.setEmail(request.getParameter("email"));
              employee.setStatus(request.getParameter("status"));
  
              String employeeId = request.getParameter("email");
  
                  employee.setEmail(employeeId);
                  dao.addEmployee(employee);              
  
              RequestDispatcher view = request.getRequestDispatcher(employee_listing);
              request.setAttribute("employees", dao.getAllEmployees());
              view.forward(request, response);            
          }
  </code></pre>
  
  <p><strong>EmployeeDao.java</strong></p>
  
  <pre><code>HttpServletRequest request;   
  
     public void addEmployee(Employee employee) throws ServletException, IOException{
          try {
              PreparedStatement preparedStatement = conn.prepareStatement("insert into login(firstname, lastname, email, pass, role, status) values (?, ?, ?, ?, 'employee', ?)");                               
              preparedStatement.setString(1, employee.getFirstname());            
              preparedStatement.setString(2, employee.getLastname());
              preparedStatement.setString(3, employee.getEmail());
              //preparedStatement.setString(4, employee.getFirstname());
              preparedStatement.setInt(4, employee.getFirstname().hashCode());
              preparedStatement.setString(5, employee.getStatus());
              //preparedStatement.setBoolean(4, employee.getStatus());
              int i = preparedStatement.executeUpdate();
              if(i &gt; 0){
                  System.out.println("Employee added successfully.");
                  HttpSession session = request.getSession();
                  session.setAttribute("successMessage", "Employee added successfully.");
              }
          } catch (SQLException e) {
              // TODO Auto-generated catch block
              System.out.println(e);
              //e.printStackTrace();
          }
      }
  </code></pre>
  
  <p><strong>addEmployee.jsp</strong></p>
  
  <pre><code>&lt;form class="form-horizontal" method="post" action="EmployeeController" name="frmAddEmployee" id="frmAddEmployee"&gt;
                                  &lt;!-- &lt;form class="form-horizontal" method="post" action="adduser.jsp" name="frmAddEmployee" id="frmAddEmployee"&gt; --&gt;
                                      &lt;div class="form-group"&gt;
                                          &lt;label for="" class="col-sm-4 control-label"&gt;First Name&lt;/label&gt;
                                          &lt;div class="col-sm-8"&gt;
                                            &lt;input type="text" name="firstName" class="form-control" id="firstName"&gt;
                                          &lt;/div&gt;
                                      &lt;/div&gt;
                                      &lt;div class="form-group"&gt;
                                          &lt;label for="" class="col-sm-4 control-label"&gt;Last Name&lt;/label&gt;
                                          &lt;div class="col-sm-8"&gt;
                                            &lt;input type="text" name="lastName" class="form-control" id="lastName" &gt;
                                          &lt;/div&gt;
                                      &lt;/div&gt;
                                      &lt;div class="form-group"&gt;
                                          &lt;label for="" class="col-sm-4 control-label"&gt;Email&lt;/label&gt;
                                          &lt;div class="col-sm-8"&gt;
                                            &lt;input type="email" name="email" class="form-control" id="email" &gt;
                                          &lt;/div&gt;
                                      &lt;/div&gt;
                                      &lt;div class="form-group"&gt;
                                          &lt;label class="col-sm-4 control-label"&gt;Employee Status&lt;/label&gt;
                                          &lt;div class="col-sm-8"&gt;
                                              &lt;label class="switch"&gt;
                                                  &lt;input type="checkbox" name="status" value="1" checked&gt;
                                                  &lt;div class="slider round"&gt;&lt;/div&gt;
                                              &lt;/label&gt;
                                          &lt;/div&gt;
                                      &lt;/div&gt;
                                      &lt;div class="form-group"&gt;
                                          &lt;div class="col-sm-4"&gt;&lt;/div&gt;
                                          &lt;div class="col-sm-8"&gt;
                                              &lt;input type="submit" name="submit" value="Submit" class="btn btn-primary"&gt; &amp;nbsp; &lt;!-- &lt;button name="cancel"  onclick='employee-listing.jsp' class="btn btn-primary" &gt;Cancel&lt;/button&gt; --&gt;
                                          &lt;/div&gt;
                                      &lt;/div&gt;
                                  &lt;/form&gt; 
  </code></pre>
  
  <p>So basically when submit the form It redirects to EmployeeController.java file and get all the values in Employee and then redirect to EmployeeDao.java file to addEmployee(employee);</p>
  
  <p>And I will get this in jsp page like ::</p>
  
  <pre><code>session.getAttribute("successMessage");
  </code></pre>
  
  <p>I tried all this but i didn't get any message form "successMessage" attribute and got only "null" value.</p>
  
  <p>I also tried to <code>response.sendRedirect("employee-success.jsp")</code> but still it didnt redirect to that page.</p>
  
  <p>So can anyone help me to set the value in java code and get that value in jsp page for further use.</p>