webtier@glassfish.java.net

Re: [webtier] Urgent: help needed

From: <webtier_at_javadesktop.org>
Date: Wed, 12 Nov 2008 09:18:18 PST

I am using validators for the first time.
LoginAction Code
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package va.fsc;

import org.apache.log4j.Logger;
import org.apache.log4j.LogManager;
import java.sql.SQLException;
import va.fsc.dao.UserDAOOracleImpl;
import com.opensymphony.xwork2.ActionSupport;
import java.util.Map;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.ServletResponseAware;
import org.apache.struts2.interceptor.SessionAware;
import org.apache.struts2.util.ServletContextAware;

/**
 *
 * @author ehurley
 */
public class loginAction extends ActionSupport
        implements SessionAware, ServletRequestAware, ServletResponseAware, ServletContextAware
{
    protected Logger log = LogManager.getLogger(va.fsc.loginAction.class);
   
    private ServletContext sc;
    private HttpServletRequest req;
    private HttpServletResponse res;
    private Map sessionMap;
    
    private String username;
    private String password;
    private String chgpswd;
    UserDAOOracleImpl imp = new UserDAOOracleImpl();
    boolean isInvalidLogin = true;
    String encrypted_password;
   
    
    @Override
     public String execute() throws Exception {
       
       LOG.info("Login: execute() method is called, username = " + username);
       if (isInvalid(getUsername())) return INPUT;
       if (isInvalid(getPassword())) return INPUT;
/*
       EncryptMD5 md = new EncryptMD5();
       encrypted_password = md.encrypt(password);
       if (getChgpswd().equalsIgnoreCase("true")){
        log.info("Going to change password");
        return "chgpswd";
        }
       if (isInvalidLogin()){
           return INPUT;
       }
 */
        return SUCCESS;
    }
 
    private boolean isInvalid(String value) {
        return (value == null || value.length() == 0);
    }
 /*
    private boolean isInvalidLogin()
                throws SQLException{
        try{
            isInvalidLogin = imp.getLogin(username, encrypted_password);
        }catch (SQLException ex){
            log.error("SQL Exception - Login: " + ex.toString());
        }
        return isInvalidLogin;
    }
*/
    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;
    }
    
    public String getChgpswd() {
        return chgpswd;
    }
    
    public void setChgpswd(String chgpswd) {
        this.chgpswd = chgpswd;
    }
    
   public void setServletRequest(HttpServletRequest req){
           this.req = req;
   }

    public void setServletResponse(HttpServletResponse res){
           this.res = res;
   }
    
    public void setServletContext(ServletContext sc){
           this.sc = sc;
   }
    
   public void setSession(Map map){
       this.sessionMap = map;
   }

   
    
    
}

LoginAction-validation.xml
<!DOCTYPE validators PUBLIC
    "-//OpenSymphony Group//XWork Validator 1.0.2//EN"
    "http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd">
    
<validators>
    <field name="username">
        <field-validator type="requiredstring">
            <message>User Name is Required</message>
        </field-validator>
        <field-validator type="stringthlength">
            <param name="minLength">5</param>
            <message>User name must be greater than (5) characters</message>
        </field-validator>
    </field>
    <field name="password">
        <field-validator type="requiredstring">
            <message>Password is Required</message>
        </field-validator>
    </field>
</validators>
[Message sent by forum member 'echurley' (echurley)]

http://forums.java.net/jive/thread.jspa?messageID=316337