title: Use a created object in servlet in JSP/forward object from servlet to JSP
body: <p>As the title says, I am trying to use the same object created in the servlet in my JSP. The object is a model (called "customer" which holds the values/data. I am setting the values in the servlet and getting/printing them in my JSP. </p>
  
  <p>I tried creating a new object in the JSP, but the value becomes null. </p>
  
  <p>At the moment, the variables and the get-methods in the customer class are static. This works, but I don't want them static.
  In order to to that, I have to fetch the existing object in my servlet and re-use it in my JSP. </p>
  
  <p>Before anyone says that I should read up, trust me, I have. I just don't understand it properly and I want someone to help me. Please. </p>
  
  <p>This is as far as I have come:</p>
  
  <p>Servlet:</p>
  
  <pre><code>String firstName = request.getParameter("förnamn");
  Customer control = new Customer ();
  control.setFirstName(firstName);
  HttpSession session = request.getSession();
  session.setAttribute("förnamn", firstName);
  
     request.setAttribute("control", control);
          RequestDispatcher view =     request.getRequestDispatcher("result.jsp");
          view.forward(request, response); 
  </code></pre>
  
  <p>This is the customer class: </p>
  
  <pre><code>private static String firstName;
  public static String getFirstName() {
      return firstName;
  }
  public static void setFirstName(String firstName) {
      Customer.firstName = firstName;
  }
  </code></pre>
  
  <p>This is my JSP:</p>
  
  <pre><code>&lt;%@ page language="java" contentType="text/html; charset=UTF-8"
  pageEncoding="UTF-8"%&gt;
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"    "http://www.w3.org/TR/html4/loose.dtd"&gt;
   &lt;html&gt;
  
  &lt;head&gt;
   &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt;
   &lt;title&gt;Your information in JSP Format:&lt;/title&gt;
   &lt;%@ page import="Abdi.Customer" %&gt;
   &lt;%HttpSessionListenerTest http = new HttpSessionListenerTest();%&gt;
  &lt;/head&gt;
  &lt;body&gt;
  
  &lt;ul&gt;
  &lt;li&gt;&lt;p&gt;&lt;b&gt;Last Name:&lt;/b&gt;
   &lt;%= Customer.getFirstName() // i want to print it, without using  static methods%&gt;
  &lt;/p&gt;&lt;/li&gt;
  
  
   &lt;/ul&gt;
  </code></pre>
  
  <p>
  </p>