title: Login form with MySQL via JDBC: Model driven in Struts 2
body: <p>I am new to struts2. I am using  NetBeans8, Glassfish4 and MySql6.</p>
  
  <p>I am making a login form. The problem I am having is is that I am not getting either an error or any output.</p>
  
  <p>I can run my application and at my login page after clicking on submit nothing happens, but my url changes to <code>http://localhost:8080/Pharma/loginAction.action</code></p>
  
  <p>Please could somebody help, your suggestions would be highly appreciated</p>
  
  <p>LoginAction.java</p>
  
  <pre><code>package package_login;
  
  import com.opensymphony.xwork2.ActionSupport;
  import com.opensymphony.xwork2.ModelDriven;
  import java.sql.Connection;
  import java.sql.DriverManager;
  import java.sql.SQLException;
  import java.sql.Statement;
  import java.util.logging.Level;
  import java.util.logging.Logger;
  import org.apache.commons.lang3.StringUtils;
  
  
  public class LoginAction extends ActionSupport implements ModelDriven&lt;User&gt;{
      User user=new User();
  
      public User getUser() {
          return user;
      }
  
      public void setUser(User user) {
          this.user = user;
      }
  
      @Override
      public User getModel() {   
         return user;
      }
       public void validate(){
       if(StringUtils.isEmpty(user.getEmail())){
           addFieldError("email","Please entered your email");
       }
  
        if(StringUtils.isEmpty(user.getPassword())){
           addFieldError("password","Please entered your password");
       }
  
       }
  
  
      public String execute() throws ClassNotFoundException, SQLException {
          LoginService loginService= new LoginService();
          if(loginService.verifyLogin(user)){
        return "logged";
  }
  return "login";
  }
  }
  </code></pre>
  
  <p>LoginService.java</p>
  
  <pre><code>package package_login;
  
  import java.sql.Connection;
  import java.sql.DriverManager;
  import java.sql.ResultSet;
  import java.sql.SQLException;
  import java.sql.Statement;
  
  
      class LoginService {
          public boolean verifyLogin(User user) throws ClassNotFoundException, SQLException{
              Class.forName("com.mysql.jdbc.Driver");
              Connection con= DriverManager.getConnection("jdbc:mysql://localhost:3306/erp","root","ali$");
              Statement st= con.createStatement();
              ResultSet rs= st.executeQuery("select password,email from login where email='"+user.getEmail()+"'" );
              while(rs.next()){
             //   if(user.getEmail().equals(rs.getString("email"))&amp;&amp; user.getPassword().equals("password")){
              //    return true;
                 }
             // }
              return false;
          }
  
      }
  </code></pre>
  
  <p>User.java</p>
  
  <pre><code>package package_login;
  
  
  class User {
      private String email;
      private String password;
  
      public String getEmail() {
          return email;
      }
  
      public void setEmail(String email) {
          this.email = email;
      }
  
      public String getPassword() {
          return password;
      }
  
      public void setPassword(String password) {
          this.password = password;
      }
  
  }
  </code></pre>
  
  <p>login.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;!DOCTYPE struts PUBLIC
  "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
  "http://struts.apache.org/dtds/struts-2.0.dtd"&gt;
  
  &lt;struts&gt;
  
      &lt;!-- Configuration for the default package. --&gt;
      &lt;package name="package_login" extends="struts-default"&gt;
          &lt;action name="loginAction" class="package_login.LoginAction"&gt;
              &lt;result name="logged"&gt;/welcome.jsp&lt;/result&gt;
              &lt;result name="login"&gt;/login.jsp&lt;/result&gt;
              &lt;result name="input"&gt;/login.jsp&lt;/result&gt;
          &lt;/action&gt;
      &lt;/package&gt;
  &lt;/struts&gt;
  </code></pre>
  
  <p>login.jsp</p>
  
  <pre><code>&lt;%@taglib uri="/struts-tags" prefix="s"%&gt;
  &lt;%@page contentType="text/html" pageEncoding="UTF-8"%&gt;
  &lt;!DOCTYPE html&gt;
  &lt;html&gt;
      &lt;head&gt;
          &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt;
          &lt;title&gt;JSP Page&lt;/title&gt;
      &lt;/head&gt;
      &lt;body&gt;
          &lt;s:form action="loginAction"&gt;
              &lt;s:textfield key="email" label="Email"/&gt;
              &lt;s:password key="password" label="Password"/&gt;
              &lt;s:submit value="login"/&gt;
          &lt;/s:form&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>