PHP8.1.21版本已发布
vue8.1.21版本已发布
jquery8.1.21版本已发布

return的转向方法

巴扎黑
巴扎黑 原创
2016-12-06 11:26:10 1055浏览

return的转向方法 
>用redirect时是要遍历一下最后的方法 
    @RequestMapping(value = "list") 
    public String list(HttpServletRequest request,HttpServletResponse response, 
                       @RequestParam Map<String, String> paramMap, 
                       Model model) { 
        directionService.findPageQuery(request, response, paramMap, model); 
        Page<Student> page =  studentService.findPageQuery(request, response,paramMap, model); 
        model.addAttribute("page", page); 
        return VIEW_PATH + "/direction/studentDirectionList"; 
      } 
     如:return "redirect:" + Global.getAdminPath() + "/direction/list";返回页面就是list方法返回的(list是方法)。 

>return VIEW_PATH + "/direction/studentDirectionConfig";则直接经过本方法中的所有代码之后直接返回到所要跳转的页面(studentDirectionConfig是页面)。 

>用Ajax提交: 
    第一步:ajax提交给servlet数据,进过相关的处理 
    第二步:servlet后可以通过下面的方法返回msg数据给前台:String msg= "error";  response.getWriter().write(msg); 
           返回信息!(如果是要转跳进行第三部,否则对返回的信息做相应的处理,如本例子的弹出提示框。) 
    第三部:通过前台中的js来实现页面跳转(如果是放在web-inf中jsp,jsp要在web.xml中部署后,这样的url才会有效,参考:http://blog.csdn.net/wanghaiping1993/article/details/23510411中关于web-inf中jsp如何访问)window.location.href="//m.sbmmt.com/m/faq/${pageContext.request.contextPath}/main.jsp" ; 

用Ajax提交表单: 
第一步:写好form表单后,向servlet提交信息 
第二部:通过下面的语句进行重定向来实现页面跳转(这样使用,在web-inf中jsp就不用在web-inf中进行部署了) 
request.getRequestDispatcher("/WEB-INF/ jsp/***.jsp").forward(request, response); 
示例: 
    <script type="text/javascript"> 
    function sub(){ 
        $("#addForm").ajaxSubmit({ 
            target:'#ajax_target' 
        }); 
    } 
    </script> 
    <button id="btnSubmit" onclick="sub()"type="button" class="btn btn-info"> 
        <i class="ace-icon glyphicon glyphicon-ok bigger-110"></i> 
            提交 
    </button> 
    <a id="btnCancel" class="btn"onclick="pageRedirect('addForm','${ctx}/direction/list')" style="cursor:pointer;" data-trigger="ajax" data-target="#ajax_target"> 
        <i class="ace-icon fa fa-undo bigger-110"></i> 
            返回 
     </a> 
可以用botton,也可以用链接设置按钮,但要加class="btn"来固定按钮形状。

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。