title: How to pass parameters from Servlet via Bean to JSP page with the help of Session?
body: <p>As mentioned below I have made changes to the code which looks like following example, but it doesn't show firstname and lastname in JSP:</p>
  
  <p>Servlet code:</p>
  
  <pre><code>//....
  HttpSession session = request.getSession();
  Person person = (Person) session.getAttribute("person");
  if (person == null) {
      person = new Person();                      
  }
  person.setNewId(newId);
  person.setFirstName(firstName);
  person.setLastName(lastName);
  session.setAttribute("person", person);
  
  RequestDispatcher rd = request.getRequestDispatcher("jsp Address");
  rd.forward(request, response);
  </code></pre>
  
  <p>Person Bean code: </p>
  
  <pre><code>private int newId;
  private String firstName;
  private String lastName;
  
  // Default Constructor
  public Person() {}
  
  public Person(int newId, String firstName, String lastName) {
      setNewId(newId);
      setFirstName(firstName);
      setLastName(lastName);
  }
  
  //Getter and Setter Methods
  public int getNewId() {return newId;}
  public void setNewId(int newID) {this.newId = newID;}
  public String getFirstName() {return firstName;}
  public void setFirstName(String FirstName) {this.firstName = FirstName;}
  public String getLastName() {return lastName;}
  public void setLastName(String LastName) {this.lastName = LastName;}
  </code></pre>
  
  <p>And in JSP code:</p>
  
  <pre><code>&lt;jsp:useBean id="person" type="app.models.Person" scope="session"&gt;
      &lt;jsp:getProperty name="person" property="firstName" /&gt;
      &lt;jsp:getProperty name="person" property="lastName" /&gt;
  &lt;/jsp:useBean&gt;
  </code></pre>
  
  <p>Output of this JSP page: none </p>
  
  <p>Expected output: firstName lastName</p>
  
  <p>Questions: </p>
  
  <pre><code>1. How can i pass parameters from Servlets to JSP via Bean with help of Session? 
  2. Is there a better way to do this code? I am using MVC architecture.
  </code></pre>