There is no reason why Struts can't figure out the URL and give it back. I have not seen the JSON result used the way you have it configured. Typically, you see the JSON result with a root parameter. The root is the action property you want to be the root of your JSON object graph.
So what I would do is create an action member called targetUrl and create a getter getTargetUrl(). Then I would set the value of this member to whatever, targetUrl = "/pages/selectBook.jsp". If the username is a match then you return SUCCESS. You don't even have to set the root since it will return the action as the root by default. In your data you just look for data.targetUrl and you should see what you need. There are other patterns: you could use another property for errorMessages when the login is no good, or use the same string. You can use a collection, etc. fireapple wrote: > > I created a login page with jQuery, I'm sending Ajax request by > .getJSON(), Also, I want to use struts 2's controller to assign to > different pages based on the returned results of action (in this case, if > username and password doesn't match, use an ajax reminder; if match, > redirect to another page, say selectBook.jsp) > > in struts.xml, I used > > [code] <action name="Login" class="tutorial.LoginDataAction"> > <result name ="success" > type="json">/pages/selectBook.jsp</result> > <result name="failed" type="json"/> > </action> > [/code] > > However, it doesn't work (means if the username and password match, it > wouldn't go to page selectBook.jsp). > > With google, I know I can solve it in this way: In login.jsp, > [code] function login() > { > var unameval = $("#username").val(); > var pwordval = $("#password").val(); > $.getJSON("Login.action", {username:unameval, > password:pwordval}, > getData); > } > > function getData(json) > { > var data = json; > if(data.redirect == 1) > top.location.href="/Test/pages/selectBook.jsp";//redirection > else > $("#status").html(data.comment);; > } > [/code] > > The problem is, in this way, the controller doesn't determine the redirect > page, which is not what struts 2 should be. > > Any suggestions about this issue, instead of the method above(change > callback function of login.jsp based on json data)? Thanks! > -- View this message in context: http://www.nabble.com/how-to-use-struts-2-to-redirect-jQuery-Ajax-request-tp23605756p23624519.html Sent from the Struts - User mailing list archive at Nabble.com. --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org