NutzCN Logo
问答 前台跳转奇怪问题,高手快看
发布于 2384天前 作者 wx_2qdej6bq3uup10lk4o79 2169 次浏览 复制 上一个帖子 下一个帖子
标签:

我们需要在OA系统里面集成使用nutz框架写的一套系统,给他传了用户名和密码,后台验证成功之后,前台跳转路径到JSP页面不成功,请问前台能不能直接跳到jsp办面,不进行映射,,跳转的路径在webroot/jsp/ifram/mian.jsp,单独使用系统时一切正常~~
直接上前台代码:

 <script>
        function next_captcha() {
            $("#captcha_img").attr("src", "${base}/captcha/next?_=" + new Date().getTime());
        }
        var me = '<%=session.getAttribute("me") %>';
        var base = '${base}';
        $(function() {
            $("#wp-submit").click(function() {
                $.ajax({
                    url : base + "/user/login",
                    type: "POST",
                    data:$('#loginForm').serialize(),
                    error: function(XMLHttpRequest, textStatus, errorThrown) {
                    	 alert(XMLHttpRequest.status);
                    	 alert(XMLHttpRequest.readyState);
                    	 alert(textStatus);
                    },
                    dataType:"json",
                    success: function(data) {
                    	  if (data && data.ok) {
                              window.location.href=base+'/menu/main?height='+$(window).height();
                          } else {
                              alert(data.msg);
                          }
                    }
                });
                return false;
            });
            
           
        });
        </script>
下面是后台的代码:


@At
@POST
public Object login(
@Param("account") String account,
@Param("password") String password,
@Param("captcha") String captcha,
@Attr(scope = Scope.SESSION, value = "nutz_captcha") String _captcha,
HttpSession session) {
NutMap re = new NutMap();
// if (!Toolkit.checkCaptcha(_captcha, captcha)) {
// return re.setv("ok", false).setv("msg", "验证码错误");
// }
int userId = userService.fetch(account, password);
if (userId < 0) {
return re.setv("ok", false).setv("msg", "用户名或密码错误");
} else {
session.setAttribute("me", userId);
// 完成nutdao_realm后启用.
SecurityUtils.getSubject().login(new SimpleShiroToken(userId));
return re.setv("ok", true);
}
}

```
用户名和密码验证成功之后,前台显示{"ok":true} 这个,,,如何直接跳转到mian.jsp界面

25 回复

@wendal 你的意思是我直接在后台一跳转?

当前是@Ok("json") 改成其他jsp或者forward咯

@At
	@POST
	@Ok("jsp:${obj.ok == true ? 'jsp.frame.main' : 'index.jsp'}")
	public Object login(
			@Param("account") String account,
			@Param("password") String password,
			@Param("captcha") String captcha,
			@Attr(scope = Scope.SESSION, value = "nutz_captcha") String _captcha,
			HttpSession session) {
		NutMap re = new NutMap();
		// if (!Toolkit.checkCaptcha(_captcha, captcha)) {
		// return re.setv("ok", false).setv("msg", "验证码错误");
		// }
		int userId = userService.fetch(account, password);
		if (userId < 0) {
			return re.setv("ok", false).setv("msg", "用户名或密码错误");
		} else {
			session.setAttribute("me", userId);
			// 完成nutdao_realm后启用.
			SecurityUtils.getSubject().login(new SimpleShiroToken(userId));
			return re.setv("ok", true);
		}
	}

这样?我前台jsp界面后面加了自适应的参数,不行阿,请高手再讲下,谢谢了@wendal

js里面写的不是jsp路径呢,用forward吧

跳转不了啊,有没有遇到过同类问题的!!!@wendal

 success: function(data) {
                    	  if (data && data.ok) {
                              <jsp:forward page=<%request.getAttribute("base")%>+"/menu/main?height="+$(window).height();
                          } else {
                              alert(data.msg);
                          }
                    }

这样还是不行,看返回的值{"ok":true}就没有对成功返回的值进行判断,杂回事?

我说的是@ok里面的forward

@At
 @POST
@("forward:/jsp/frame/main")
 public Object login(
 @Param("account") String account,
 @Param("password") String password,
 @Param("captcha") String captcha,
 @Attr(scope = Scope.SESSION, value = "nutz_captcha") String _captcha,
 HttpSession session) {
 NutMap re = new NutMap();
 // if (!Toolkit.checkCaptcha(_captcha, captcha)) {
 // return re.setv("ok", false).setv("msg", "验证码错误");
 // }
 int userId = userService.fetch(account, password);
 if (userId < 0) {
 return re.setv("ok", false).setv("msg", "用户名或密码错误");
 } else {
 session.setAttribute("me", userId);
 // 完成nutdao_realm后启用.
 SecurityUtils.getSubject().login(new SimpleShiroToken(userId));
 return re.setv("ok", true);
 }
 }   返回时报404错误,返回的界面如何再后面加一个height的参数,@wendal看下~~
@("forward:/frame/main")

main.jsp的路径是webroot/jsp/frame/main.jsp 还是不行,几种方法都试了~~~

根据你最初贴的js代码, 登录成功后,调整的是页面是 /menu/main

window.location.href=base+'/menu/main?height='+$(window).height();

所以, 写成下面这样试试

@Ok("->:/menu/main")

还是一样的效果,跳转不了,,这什么原因呢?

怎样的跳转不? 你提交用户名密码的时候走表单还是ajax的?

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>


<!DOCTYPE html>
<html class=" ">
    <head>
   
        <meta http-equiv="content-type" content="text/html;charset=UTF-8" />
        <meta charset="utf-8" />
        <title>11111</title>
        <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
        <meta content="" name="description" />
        <meta content="" name="author" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />    <!-- Favicon -->
		<link href="assets/css/loginstyle.css" rel="stylesheet" type="text/css">
		<script src="assets/js/jquery-2.1.4.min.js"  type="text/javascript"></script> 
		<script type="text/javascript" src="assets/js/jquery.ez-bg-resize.js"></script>
		
        <!-- CORE CSS TEMPLATE - END -->
        <script>
        function next_captcha() {
            $("#captcha_img").attr("src", "${base}/captcha/next?_=" + new Date().getTime());
        }
        var me = '<%=session.getAttribute("me") %>';
        var base = '${base}';
        $(function() {
            $("#wp-submit").click(function() {
                $.ajax({
                    url : base + "/user/login",
                    type: "POST",
                    data:$('#loginForm').serialize(),
                    error: function(XMLHttpRequest, textStatus, errorThrown) {
                    	 alert(XMLHttpRequest.status);
                    	 alert(XMLHttpRequest.readyState);
                    	 alert(textStatus);
                    },
                    dataType:"json",
                    success: function(data) {
                    	  if (data && data.ok) {
                              window.location.href=base+'/menu/main?height='+$(window).height();
                          } else {
                              alert(data.msg);
                          }
                    }
                });
                return false;
            });
            
           
        });
        </script>

    </head>
    <!-- END HEAD -->

    <!-- BEGIN BODY -->
    <body >
    <script type="text/javascript">
    $(document).ready(function() {
        $("body").ezBgResize({
            img     : "assets/images/body_bg.jpg", // Relative path example.  You could also use an absolute url (http://...).
            opacity : 1, // Opacity. 1 = 100%.  This is optional.
            center  : true // Boolean (true or false). This is optional. Default is true.
        });
    });
</script>
<script type="javascript">
    $(window).resize(function(){
        $('.yd_center').css({
            position:'absolute',
            left: ($(window).width() - $('.yd_center').outerWidth())/2,
            top: ($(window).height() - $('.yd_center').outerHeight())/2 + $(document).scrollTop()
        });
    });
    //初始化函数
    $(window).resize();
</script>
     <div class="copright">

</div>
<div class="yd_center">
<form action="#" id="loginForm" method="post">
<table width="445" border="0" cellpadding="0" cellspacing="0" class="login_box">
  <tr>
    <td height="457" colspan="4" align="center" valign="top"><table width="330" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td height="224">&nbsp;</td>
      </tr>
      <tr>
        <td height="56"><label for="textfield"></label>
          <input type="text"  placeholder="账 号"  name="account" id="user_login" class="lo_zh" /></td>
      </tr>
      <tr>
        <td height="56"><label for="textfield2"></label>
          <input type="password" placeholder="密 码"  name="password" id="user_pass" autocomplete="off"    class="lo_mm"/></td>
      </tr>
      <tr>
        <td height="90"><input type="image" name="button" id="wp-submit" value="提交"  src="assets/images/login_btn.png" class="lo_dl"/></td>
      </tr>
    </table></td>
  </tr>
  </table>
</form>
</div>
    

</body>
</html>

这是我前台的完整代码 。


    
@At
	@POST
	@Ok("->:/menu/admin")
	public Object login(
			@Param("account") String account,
			@Param("password") String password,
			@Param("captcha") String captcha,
			@Attr(scope = Scope.SESSION, value = "nutz_captcha") String _captcha,
			HttpSession session) {
		NutMap re = new NutMap();
		// if (!Toolkit.checkCaptcha(_captcha, captcha)) {
		// return re.setv("ok", false).setv("msg", "验证码错误");
		// }
		int userId = userService.fetch(account, password);
		if (userId < 0) {
			return re.setv("ok", false).setv("msg", "用户名或密码错误");
		} else {
			session.setAttribute("me", userId);
			// 完成nutdao_realm后启用.
			SecurityUtils.getSubject().login(new SimpleShiroToken(userId));
			return re.setv("ok", true);
		}
	}
这是后台验证代码~~
@IocBean // 声明为Ioc容器中的一个Bean
@At("/menu") // 整个模块的路径前缀
@Fail("http:500") // 抛出异常的话,就走500页面
public class MenuModule {

    @Inject // 注入同名的一个ioc对象
    protected Dao dao;

    @Inject protected UserService userService;
    
    @RequiresUser
    @GET
    @At("/main")
    @Ok("jsp:jsp.frame.main") // 降内部重定向到mainjsp
    public void mainPage() {}
 

提交的路径映射类。。没撒问题么~~~怎么回事?

所以, 你依然是ajax提交, 然后用js来跳转的嘛

@Ok("json:full")

然后在这里打断点

                    success: function(data) {
                    	  if (data && data.ok) {
                              window.location.href=base+'/menu/main?height='+$(window).height();
                          } else {
                              alert(data.msg);
                          }
                    }

```
@At
@POST
@Ok("jsp:${obj.ok==true?'jsp.frame.main':'/index'}")
public Object login2(
@Param("account") String account,
@Param("password") String password,
@Param("captcha") String captcha,
@Attr(scope = Scope.SESSION, value = "nutz_captcha") String _captcha,
HttpSession session) {
NutMap re = new NutMap();
// if (!Toolkit.checkCaptcha(_captcha, captcha)) {
// return re.setv("ok", false).setv("msg", "验证码错误");
// }
int userId = userService.fetch(account, password);
if (userId < 0) {
return re.setv("ok", false).setv("msg", "用户名或密码错误");
} else {
session.setAttribute("me", userId);
// 完成nutdao_realm后启用.
SecurityUtils.getSubject().login(new SimpleShiroToken(userId));
return re.setv("ok", true);
}
}
单独给它一个方法让去跳转,但是ok为false时跳不到index.jsp页面,index.jsp在webroot/index.jsp,如何跳呢??@wendal

你到底是不是用ajax去请求这个login入口的?

系统是要集成到泛微里面,用户名和密码提前设定好,难证路径也是设好的

到底是不是ajax访问login入口!!!

// 登录失败时
return new JspView("/user/login.jsp");

// 登录成功时
return new Forward("/menu/main");

已能正常跳转,非常感谢~~~

添加回复
请先登陆
回到顶部