日期:2014-05-17  浏览次数:20734 次

Struts2调用完action方法后无法实现页面跳转
本帖最后由 yangfei_01 于 2011-11-12 22:15:31 编辑
    今天写一个SSH的demo,用的Struts2,在登录页面用户用ajax向后台请求登录。

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");
            }
        });
}

经过后台处理验证,action的execute方法正常返回Action.SUCCESS或Action.INPUT,返回到struts.xml中时也正确获得了home.jsp页面或index.jsp页面(ajax返回的result结果中已经验证返回的确实是jsp页面),但是执行结束后整体页面没有跳转。

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>

同时如果在页面直接请求http://localhost:8080/sshTest/login.do?username=name&password=pwd就会正常调用login的action并且跳转页面,折腾好半天没解决了,不知道谁遇到过类似的问题,诚求高手解答。

------解决方案--------------------
用ajax跳转页面。。。
LZ没有明白ajax的作用是什么

------解决方案--------------------
ajax 是可以无刷新操作的,不用跳转D,直接跟后台交互数据
------解决方案--------------------
ajax是不会跳转页面的,你只是把值送到了你要跳到的页面,但是不会跳过去,要明白异步的道理
------解决方案--------------------
ajax属于异步提交,当然是不会跳转的,你用表单提交,就会跳转的