Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Clearing error messages after refresh

843840Oct 13 2008 — edited Oct 14 2008
Hello Experts,

I have done a web application using struts in which i need to clear the error message like Invalid user name and password., after pressing refresh button. let me tell you clearly. In Login page end-user has to provide user name and passowrd, if this is wrong at LoginAction
i set a request attribute with an error message and forward the control to login jsp where i have the following code
            if(request.getAttribute("logerr")!=null){
                out.println(request.getAttribute("logerr").toString());
                request.removeAttribute("logerr");                
            }
when i refresh the current login page after getting this error, there should not be this message, since there is no value for user name and password typed.

my bean
/*
 * LoginForm.java
 *
 * Created on October 4, 2006, 3:31 PM
 */

package forms;

import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;

/**
 *
 * @author srinivas
 * @version
 */

public class LoginForm extends org.apache.struts.action.ActionForm {
    
     private String userId;
     private String password;
     
    public String getUserId()
    {
        return userId;
    }
    
    public void setUserId(String userId)
    {
        this.userId =  userId;
    }
    
    public String getPassword()
    {
        return password;
    }
    
    public void setPassword(String userPass)
    {
        this.password = userPass;
    }
    
    public void reset(ActionMapping mapping, HttpServletRequest request)
    {
        
        this.userId= "";
        this.password= "";
    }
    
    
   
    public ActionErrors validate(ActionMapping mapping,HttpServletRequest request)
    {       
        ActionErrors errors = new ActionErrors();
            
          if(userId==null || userId.length()== 0)
        {           
             errors.add("userId",new org.apache.struts.action.ActionError("error.userId"));            
        }
        if(password==null || password.length()== 0)
        {
            errors.add("password",new org.apache.struts.action.ActionError("error.password"));                             
        }

       return errors; 
        
    }
   
    
    }
Please help me out, Any help will be greatly appreciated.

Thanks & Regards,
Sri.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 11 2008
Added on Oct 13 2008
3 comments
1,652 views