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" οnclick="sub()"type="button" class="btn btn-info">
<i class="ace-icon glyphicon glyphicon-ok bigger-110"></i>
提交
</button>
<a id="btnCancel" class="btn"οnclick="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"来固定按钮形状。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值