标签:
问题描述:Spring mvc , Controller页面重定向,数据正常传递,页面不跳转。例:StudentAssess.jsp在Controller中页面重定向到StudentExaming.jsp
核心代码:
StudentAssess.jsp:
<span style="font-size:18px;">function queryExamineeArrangement(){ $.ajax({ url:'queryExamineeArrangement', type:'post', datatype:'json' }); }<span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);"> </span></span>
StudentAssessController.java:
<span style="font-size:18px;">@SuppressWarnings("unused") @RequestMapping("/queryExamineeArrangement") public String queryExamineeArrangement(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException{ try { List<ExamineeArrangement> listExamineeArrangement=studentAssessBean.queryExamineeArrangement("1000"); request.setAttribute("examState", listExamineeArrangement.get(0).getExamState()); } catch (Exception e) { e.printStackTrace(); } return "/StudentExaming"; }</span>
StudentExaming.jsp:
先通过该语句将传过来的数据打印到控制台,显示如下:
<span style="font-size:18px;">System.out.println("examState=" + request.getAttribute("examState"));</span>
问题:数据虽然已经打印出来了,但是页面依旧停留在StudentAssess.jsp
方案:
经过多方努力,终于找到了问题的所在(下图阴影部分):
使用Ajax,是进行异步提交,只会实现局部刷新,因此它是不会跳转页面的。因此正确写法如下:
<span style="font-size:18px;">System.out.println("examState=" + request.getAttribute("examState"));</span>
总结:有时候觉得手指头离心脏还很遥远呢,不至于让人死掉吧!但往往问题就在:我以为的就是我以为的地方。
标签:
原文地址:http://blog.csdn.net/wang13667539325/article/details/45850805