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"来固定按钮形状。
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号