Accessing JSP form data with in the Struts 2 Action class
<p>I don't understand how to access form data within the JSP page inside my <code>Action</code> class</p>
<p><strong><code>login.jsp</code>:</strong></p>
<pre class="lang-html prettyprint-override"><code> &lt;div class=&quot;well&quot;&gt;
    &lt;form id=&quot;loginForm&quot; method=&quot;POST&quot; action=&quot;hr/login/&quot; novalidate=&quot;novalidate&quot;&gt;
        &lt;div class=&quot;form-group&quot;&gt;
            &lt;div class=&quot;input-group&quot;&gt;
                &lt;span class=&quot;input-group-addon&quot; id=&quot;UserEmail&quot;&gt;&lt;i class=&quot;fa fa-user&quot; title=&quot;Enter Your username&quot;&gt;&lt;/i&gt;&lt;/span&gt;
                &lt;input type=&quot;text&quot; class=&quot;form-control&quot; id=&quot;username&quot; name=&quot;username&quot; value=&quot;&quot; required title=&quot;Please enter you username&quot; placeholder=&quot;Enter Username&quot; /&gt;
            &lt;/div&gt;
            &lt;span class=&quot;help-block&quot;&gt;&lt;/span&gt;
        &lt;/div&gt;
        &lt;div class=&quot;form-group&quot;&gt;
            &lt;div class=&quot;input-group&quot;&gt;
                &lt;span class=&quot;input-group-addon&quot; id=&quot;UserPasswordMatch&quot;&gt;&lt;i class=&quot;fa fa-lock&quot; title=&quot;Choose password&quot;&gt;&lt;/i&gt;&lt;/span&gt;
                &lt;input type=&quot;password&quot; class=&quot;form-control&quot; id=&quot;passwordmatch&quot; name=&quot;passwordmatch&quot; value=&quot;&quot; required title=&quot;Enter your password&quot; placeholder=&quot;Enter Password&quot; /&gt;
            &lt;/div&gt;
        &lt;/div&gt;
        &lt;button type=&quot;submit&quot; class=&quot;btn btn-success btn-block&quot;&gt;Login&lt;/button&gt;
    &lt;/form&gt;
&lt;/div&gt;
</code></pre>
<p><strong><code>BookingAction.java</code>:</strong></p>
<pre class="lang-java prettyprint-override"><code>public class BookingAction {
    private String name;
    
    HotelReservationServceImpl service = new HotelReservationServceImpl();

       public String execute() throws Exception {
        
          return &quot;success&quot;;
       }
       
       public String loginExecute() 
       {
           
           
           return &quot;success&quot;;
       }
       public String getName() {
          return name;
       }

       public void setName(String name) {
          this.name = name;
       }
}
</code></pre>
<p>I also have a <code>User</code> class with private attributes which include <code>username</code> and <code>password</code> with getters and setters.</p>
<p><strong><code>service.java</code>:</strong></p>
<pre class="lang-java prettyprint-override"><code>public class HotelReservationServceImpl implements IHotelReservationService {

    
    HotelReservationDAOImpl dbcon = new HotelReservationDAOImpl();
    @Override
    public int login(String username, String passwrd) {
        if(username.isEmpty() || passwrd.isEmpty())
        {
            System.out.print(&quot; Enter username and password &quot;);
            
        }
        else
        {
        int i = dbcon.login(username, passwrd);
        
        }
        
        
        //dbcon.dbConnector();
        return 0;
    }
}
</code></pre>
<p><strong><code>struts.xml</code>:</strong></p>
<pre class="lang-xml prettyprint-override"><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;!DOCTYPE struts PUBLIC
   &quot;-//Apache Software Foundation//DTD Struts Configuration 2.0//EN&quot;
   &quot;http://struts.apache.org/dtds/struts-2.0.dtd&quot;&gt;
&lt;struts&gt;
&lt;constant name=&quot;struts.devMode&quot; value=&quot;true&quot; /&gt;
   &lt;package name=&quot;helloworld&quot; extends=&quot;struts-default&quot;&gt;
     
      &lt;action name=&quot;hello&quot; 
            class=&quot;com.reservation.action.BookingAction&quot; 
            method=&quot;execute&quot;&gt;
            &lt;result name=&quot;success&quot;&gt;/HelloWorld.jsp&lt;/result&gt;
      &lt;/action&gt;
      &lt;action name=&quot;login&quot;
       class=&quot;com.reservation.action.BookingAction&quot; 
            method=&quot;loginExecute&quot;&gt;
            &lt;result name=&quot;success&quot;&gt;/HelloWorld.jsp&lt;/result&gt;
      &lt;/action&gt;
   &lt;/package&gt;
&lt;/struts&gt;
</code></pre>