PDA

View Full Version : Login app with struts2(different from privious thread)



pirusira
18 May 2010, 10:05 PM
Hello All,

I've been making a login app with struts2 framework.
The following are my codes.

the form panel that login info is input in :


var loginForm = new Ext.FormPanel({
url : 'Login.action',
...
buttons:[{
text:'???',
id:'btn_login',
type:'submit',
formBind: true,
handler:function(){
loginForm.getForm().submit({
method:'POST',
waitTitle:'Connecting',
waitMsg:'Sending data...',

success:function(){
Ext.Msg.alert('Status', 'Login Successful!', function(btn, text){
if (btn == 'ok'){
var redirect = 'main.jsp';
window.location = redirect;
}
});
},

failure:function(){
Ext.Msg.alert('Login Failed!');
loginForm.getForm().reset();
}
});
}
}]
});


execute() method in Login action class :


public String execute() throws Exception{
if ("admin".equals(id)) {
Map session = ActionContext.getContext().getSession();
session.put("logged_in","true");
success = "{success:true}";
return "success";
}
else{
success = "{success:false,errors:{reason:'Login failed.Try again'}}";
return "error";
}
}


config for the action in struts.xml file :


<action name="Login" class="action.Login" >
<result type="json" />
</action>


This codes works well.
But the problem is that if I attempt to login with wrong id(not 'admin') then the error is showed in the console of eclipse.
The error :
WARN at logging.commons.CommonsLogger.warn(CommonsLogger.java:49) - Could not find action or result
No result defined for action action.Login and result error

I think that the struts.xml has something wrong but I don't know it.
Can anyone help?

Thanks,
Stan