您好,欢迎访问一九零五行业门户网

return的转向方法

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=${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来固定按钮形状。
其它类似信息

推荐信息