2013年9月16日星期一

Struts2 After calling the action method can not be achieved after the page jump

 This post last edited by the yangfei_01 on 2011-11-12 22:15:31
Today wrote an SSH the demo, using Struts2, the login page user login using ajax request to background .

function userLogin() {
var uname = document.getElementById("username").value;
var upwd = document.getElementById("password").value;
$.ajax({
            type: "POST",
            url: "login.do",
            data: "username=" + uname + "&password=" + upwd,
            success: function(result) {
            },
            error: function(result) {
                alert("send false");
            }
        });
}

the spooled verification , action execute method returns normally Action.SUCCESS or Action.INPUT, when they returned to the struts.xml correctly received home.jsp pages or index.jsp page (ajax returned result results indeed proven return jsp page ) , but after the whole page is not executed jumps .

struts.xml部分代码
<package name="main" extends="struts-default">
<action name="index">
<result>index.jsp</result>
</action>
<action name="login" class="loginAction">
<result name="success">/home.jsp</result>
<result name="input">/index.jsp</result>
</action>
</package>


applicationContext.xml部分代码
<bean name="loginAction" scope="prototype" class="com.demo.actions.user.LoginAction">
<property name="userService">
<ref local="userService" />
</property>
</bean>

And if the page will direct request http://localhost:8080/sshTest/login.do?username=name&password=pwd normal call the login page of the action and jump , toss quite a while not resolved, I do not know who encountered similar problems, sincere seeking expert answers.
------ Solution ---------------------------------------- ----
using ajax jump page . . .
LZ did not understand what is the role ajax

------ Solution ------------------------------------ --------
ajax no refresh operation is possible , do not jump D, interacts directly with the background data
------ Solution ---------- ----------------------------------
ajax is not going to jump page , you just put the value of sent to the page you want to jump , but will not jump in the past , to understand the truth asynchronous
------ Solution -------------------- ------------------------
ajax is asynchronous commit , of course, is not going to jump , you use the form is submitted , it will jump

------ For reference only ---------------------------------- -----

very strange for ajax but ajax in url: "login. do " will call the login corresponding action returns without triggering a page to jump it ?
I used the form to submit jump will occur , if submitting a request can be realized using ajax and then jump to the corresponding page or action it ?
------ For reference only -------------------------------------- -
success: function (result) {

are you doing here , if successful , will come here, you plus one here
alert ('1111111111111111111111 ');
},
error: function (result) {
alert ("send false");
}

------ For reference only ---------------------------------- -----

Lane with
url: "login.do", replace the url: "/ login / login.action",


------ For reference only ---------------------------------- -----

finished action in the action in the call to return something false and True
------ For reference only ------------ ---------------------------
$. ajax ({
type: "POST",
url: "login / login.do",
data: "username =" + uname + " & password = "+ upwd,
success: function (result) {
},
error: function (result) {
alert ("send false");
}
});
URL error
function (result), result of ajax returned responseText, page jump after the success
alert (result) output the contents of your after the jump page where the entire content ( that is, the result page as a response text )

------ For reference only ------- --------------------------------


you use JQUERY AJAX call that struts.xml ACTION way you write the wrong way .
------ For reference only -------------------------------------- -
same problem , find great God who answers !
------ For reference only -------------------------------------- -
called ajax, no refresh technology is asynchronous , meaning that you use the ajax request something , he will not refresh the current page to get back in case the data returned , regardless of background, is how you return , it will get If the return is your view , he will get you a static view of the document , of course , this is also related with the configuration of your ajax (dataType), see you with the return data type is. .
This is a broad understanding of depth of understanding is necessary to understand the request and form submit ajax get and post the difference between , http protocol is stateless , form the get and post maintains a view state (viewstate ) , while the mean ajax submission after the end of the life cycle of this view , so the background can not be achieved ajax request page jump ( this is my personal understanding , there must be something wrong, but it is almost like this ) < br> ------ For reference only ---------------------------------------
encountered the same problem , LZ would like to know how to solve ?

没有评论:

发表评论