You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by red phoenix <ro...@gmail.com> on 2010/08/05 17:49:22 UTC
Struts2+json question
I use struts2.1.8 and extjs3.2, I make a login page, if login
failed,it will alert a message and it will still stay this login page;
if it login success,it will go to another new page,such as main.jsp
page
My login page is follows:
var win=new Ext.Window({
el:'hello-win',
....
items:
loginForm,
buttons:[{
text:'OK',
handler:function(){
if(win.getComponent('loginForm').form.isValid()){
win.getComponent('loginForm').form.submit({
url:'/Test/test.do',
success:function(form,action){
Ext.Msg.alert("Login success!",action.result.message);
},
failure:function(form,action){
Ext.Msg.alert('Login fail",action.result.message);
}
});
}
}
}
});
Action class is follows:
public String login() throws Exception{
boolean success;.
....
if(success){
return SUCCESS;
}
else{
setMessage("Your ID or password is wrong");
return null;
}
}
configure file is follows:
<struts>
<package name="Test" namespace="" extends="json-default">
<action name="login" class="Test.Login" method="test">
<result type="json"/>
</action>
</package>
</struts>
If I set <result>main.jsp</result>, when I click OK button,it will
raise javascript error,because extjs don't get json message.
If I set <result type="json"/>,whether I login success or fail,the
login page will don't redirect,If login success,I want to redirect
this page to main.jsp,but it don't redirect.What can I do about
configure file? I don't know how to do it.I have no idea about it.
Any idea will be appreciated!
Thanks in advance
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Struts2+json question
Posted by Steven Yang <ke...@gmail.com>.
this is the matter with how you handle your result in your javascript and
how you communicate with your javascript
in you case, you should always return a json because your doing your
validation by AJAX right?
its in your javascript that you need to tell whether the login was
successful or not, if it is then redirect.
I havent used Extjs for a while, so i dont remember whether ur syntax
actually submits the page or Ext will submit by AJAX for you
On Thu, Aug 5, 2010 at 11:49 PM, red phoenix <ro...@gmail.com> wrote:
> I use struts2.1.8 and extjs3.2, I make a login page, if login
> failed,it will alert a message and it will still stay this login page;
> if it login success,it will go to another new page,such as main.jsp
> page
>
> My login page is follows:
> var win=new Ext.Window({
> el:'hello-win',
> ....
> items:
> loginForm,
> buttons:[{
> text:'OK',
> handler:function(){
> if(win.getComponent('loginForm').form.isValid()){
> win.getComponent('loginForm').form.submit({
> url:'/Test/test.do',
> success:function(form,action){
> Ext.Msg.alert("Login success!",action.result.message);
> },
> failure:function(form,action){
> Ext.Msg.alert('Login fail",action.result.message);
> }
> });
> }
> }
> }
> });
>
> Action class is follows:
> public String login() throws Exception{
> boolean success;.
> ....
> if(success){
> return SUCCESS;
> }
> else{
> setMessage("Your ID or password is wrong");
> return null;
> }
> }
>
> configure file is follows:
> <struts>
> <package name="Test" namespace="" extends="json-default">
> <action name="login" class="Test.Login" method="test">
> <result type="json"/>
> </action>
> </package>
> </struts>
>
> If I set <result>main.jsp</result>, when I click OK button,it will
> raise javascript error,because extjs don't get json message.
> If I set <result type="json"/>,whether I login success or fail,the
> login page will don't redirect,If login success,I want to redirect
> this page to main.jsp,but it don't redirect.What can I do about
> configure file? I don't know how to do it.I have no idea about it.
> Any idea will be appreciated!
>
> Thanks in advance
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>