title: ognl.OgnlException: target is null for setProperty...?
body: <p>I'm new to Struts 2. I'm creating a demo web application which allows a user to submit employee details on a jsp and show them on the next jsp. Following is the code:</p>
  
  <p><strong>struts.xml</strong></p>
  
  <pre><code>&lt;struts&gt;
      &lt;constant name="struts.custom.i18n.resources" value="ApplicationResources" /&gt;
  
      &lt;!-- Configuration for the default package. --&gt;
      &lt;package name="default" extends="struts-default" namespace="/"&gt;
  
          &lt;action name="empDetails" class="com.webapp.test.action.MyAction"
              method="employeeDetails"&gt;
              &lt;result name="success"&gt;jsp/employeeDetails.jsp&lt;/result&gt;
          &lt;/action&gt;
  
          &lt;action name="addEmployee" class="com.webapp.test.action.MyAction"
              method="addEmployee"&gt;
              &lt;result name="success"&gt;jsp/addEmployee.jsp&lt;/result&gt;
          &lt;/action&gt;
      &lt;/package&gt;
  &lt;/struts&gt;
  </code></pre>
  
  <p><strong>Action class</strong></p>
  
  <pre><code>public class MyAction extends ActionSupport{
  
      private static final long serialVersionUID = 1L;
  
      private Employee emp = null; 
  
      public String addEmployee(){
          System.out.println("In addEmployee");
          return SUCCESS;
      }
  
      public String employeeDetails(){
          System.out.println("In employeeDetails");
          System.out.println("Employee ID: "+emp.getEmployeeID());
          return SUCCESS;
      }
  }
  </code></pre>
  
  <p>In the above action class, Employee is a separate model class with the following attributes:</p>
  
  <pre><code>String employeeID;
  String name;
  String department;
  </code></pre>
  
  <p>Following is my JSP page to add an employee:</p>
  
  <pre><code>&lt;%@taglib uri="/struts-tags" prefix="s"%&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"&gt;
  &lt;title&gt;Add Employee&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;s:form action="empDetails"&gt;
  &lt;s:textfield name="emp.employeeID" label="Employee ID"&gt;&lt;/s:textfield&gt;
  &lt;s:textfield name="emp.name" label="Name"&gt;&lt;/s:textfield&gt;
  &lt;s:textfield name="emp.department" label="Department"&gt;&lt;/s:textfield&gt;
  &lt;s:submit&gt;&lt;/s:submit&gt;
  &lt;/s:form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>After filling in the employee details when I click on the Submit button, I get a nullpointer exception in the employeeDetails() method:</p>
  
  <pre><code>java.lang.NullPointerException
      com.webapp.test.action.MyAction.employeeDetails(MyAction.java:19)
  </code></pre>
  
  <p>and the server console displays the following exceptions:</p>
  
  <pre><code>ognl.OgnlException: target is null for setProperty(null, "department", [Ljava.lang.String;@acd4c9)
  .....
  ognl.OgnlException: target is null for setProperty(null, "employeeID", [Ljava.lang.String;@c5dd98)
  ....
  ognl.OgnlException: target is null for setProperty(null, "name", [Ljava.lang.String;@5753b0)
  </code></pre>
  
  <p>Please explain what is the problem and how can I fill the employee model object from the JSP. I do not want to create getter setter methods in the Action class and also I do not want to use the ModelDriven interface.</p>