title: Struts 1 login application example error
body: <p>I am new to Struts and tried to execute Login Form. But it's not getting executed after the default constructor in the ACTION class.  </p>
  
  <hr>
  
  <p>LoginForm.java</p>
  
  <pre><code>package struts.login.action;
  
  import org.apache.struts.action.ActionForm;
  
  @SuppressWarnings("serial")
  public class LoginForm extends ActionForm {
  
  public LoginForm() {
  
  }
  
  private String username;
  private String password;
  public String getUsername() {
      return username;
  }
  public void setUsername(String username) {
      this.username = username;
  }
  public String getPassword() {
      return password;
  }
  public void setPassword(String password) {
      this.password = password;
  }
  
  
  }
  </code></pre>
  
  <p>LoginAction.java</p>
  
  <pre><code>package struts.login.action;
  
  import javax.servlet.ServletRequest;
  import javax.servlet.ServletResponse;
  
  import org.apache.struts.action.Action;
  import org.apache.struts.action.ActionForm;
  import org.apache.struts.action.ActionForward;
  import org.apache.struts.action.ActionMapping;
  
  public class LoginAction extends Action {
  
  private final static String SUCCESS = "success";
  private final static String FAILURE = "failure";
  //private final static String FAILURE = "failure";
  
  public LoginAction() {
      System.out.println("default constructor of Login Action");
  }
  
  @Override
  public ActionForward execute(ActionMapping mapping, ActionForm form,
          ServletRequest request, ServletResponse response) throws Exception     {
  
      LoginForm loginForm = (LoginForm) form;
      if(loginForm.getUsername().equals(loginForm.getPassword())){
          return mapping.findForward(SUCCESS);    
      }
      else{
          return mapping.findForward(FAILURE);    
      }
  
  }
  }
  </code></pre>
  
  <p>Login.jsp</p>
  
  <pre><code>&lt;%@ taglib uri="/WEB-INF/tld/struts-html.tld" prefix="html"%&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;title&gt;Login Page&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;div style="color:red"&gt;
  
  &lt;/div&gt;
  &lt;html:form action="/Login" method="get"&gt;
      User Name :&lt;html:text property="username"/&gt;&lt;br&gt;
      Password  :&lt;html:password property="password"/&gt;
      &lt;html:submit value="Login Here" /&gt;
  &lt;/html:form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>success.jsp</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
  &lt;title&gt;Insert title here&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  Successfully logged in!
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>failure.jsp</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
  &lt;title&gt;Insert title here&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  login failed please try again!
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>struts-config.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  
  &lt;!DOCTYPE struts-config PUBLIC
  "-//Apache Software Foundation//DTD Struts Configuration 1.3//EN"
  "http://struts.apache.org/dtds/struts-config_1_3.dtd"&gt;
  
  &lt;struts-config&gt;
  &lt;form-beans&gt;
      &lt;form-bean name="loginForm" type="struts.login.action.LoginForm"&gt;
      &lt;/form-bean&gt;
  &lt;/form-beans&gt;
  
  &lt;action-mappings&gt;
      &lt;action path="/Login" name="loginForm"             type="struts.login.action.LoginAction" &gt;
      &lt;forward name="success" path="/success.jsp"&gt;&lt;/forward&gt;
      &lt;forward name="failure" path= "/failure.jsp"&gt;&lt;/forward&gt;
      &lt;/action&gt;
  
  
  &lt;/action-mappings&gt;
  
  &lt;/struts-config&gt;
  </code></pre>
  
  <p>web.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;web-app id="WebApp_ID" version="2.5"
  xmlns="http://java.sun.com/xml/ns/javaee"    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://java.sun.com/xml/ns/javaee   http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"&gt;
  
  &lt;welcome-file-list&gt;
      &lt;welcome-file&gt;login.jsp&lt;/welcome-file&gt;
  &lt;/welcome-file-list&gt;
  &lt;!-- Standard ActionServlet Configuration --&gt;
  &lt;servlet&gt;
      &lt;servlet-name&gt;action&lt;/servlet-name&gt;
      &lt;servlet-class&gt;org.apache.struts.action.ActionServlet&lt;/servlet-class&gt;
      &lt;init-param&gt;
          &lt;param-name&gt;config&lt;/param-name&gt;
          &lt;param-value&gt;/WEB-INF/struts-config.xml&lt;/param-value&gt;
      &lt;/init-param&gt;
      &lt;init-param&gt;
          &lt;param-name&gt;application&lt;/param-name&gt;
          &lt;param-value&gt;ApplicationResources&lt;/param-value&gt;
      &lt;/init-param&gt;
      &lt;init-param&gt;
          &lt;param-name&gt;debug&lt;/param-name&gt;
          &lt;param-value&gt;3&lt;/param-value&gt;
      &lt;/init-param&gt;
      &lt;init-param&gt;
          &lt;param-name&gt;detail&lt;/param-name&gt;
          &lt;param-value&gt;3&lt;/param-value&gt;
      &lt;/init-param&gt;
      &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
  &lt;/servlet&gt;
  
  &lt;!-- Standard ActionServlet Mapping --&gt;
  &lt;servlet-mapping&gt;
      &lt;servlet-name&gt;action&lt;/servlet-name&gt;
      &lt;url-pattern&gt;*.do&lt;/url-pattern&gt;
  &lt;/servlet-mapping&gt;
  
  &lt;!-- Struts Tag Library Descriptors --&gt;
  &lt;jsp-config&gt;
  &lt;taglib&gt;
      &lt;taglib-uri&gt;/WEB-INF/tld/struts-html.tld&lt;/taglib-uri&gt;
      &lt;taglib-location&gt;/WEB-INF/tld/struts-html.tld&lt;/taglib-location&gt;
  &lt;/taglib&gt;
  &lt;/jsp-config&gt;
  &lt;/web-app&gt;
  </code></pre>
  
  <p>I have included struts-html.tld file in WEB-INF/tld folder.
  After login with username and password It's not redirected to either success.jsp or failure.jsp page</p>