大家都知道我们在springmvc3.1以后可以利用RedirectAttributes在action重定向后来进行数据传递,来解决困扰大家许久的action之间跳转数据丢失的问题。
那么我们如何在action重定向到jsp页面后通过EL表达式获取其中的参数呢?
当然你也可以使用attribute来进行页面数据的传递但是会拼接到url中,直接显示给用户,会有一定的安全问题。
测试代码:
TestController.java
@RequestMapping("wjw/login")
public String alipayforward(HttpServletRequest req, HttpServletResponse resp, final RedirectAttributes redirectAttributes) throws Exception {
redirectAttributes.addAttribute("username", "admin");
String password = new String(Base64.encodeBase64("123456".getBytes()));
redirectAttributes.addFlashAttribute("password", password);
return "redirect:/views/app/login.jsp";
}
login.jsp
<script>
$