springmvc重定向后jsp如何获取其中的flashAttribute?

本文介绍了在SpringMVC 3.1之后,如何使用RedirectAttributes在控制器重定向到JSP页面时传递数据,以避免URL中显示敏感信息。通过在action中设置flashAttribute,并在JSP页面中使用EL表达式${sessionScope['org.springframework.web.servlet.support.SessionFlashMapManager.FLASH_MAPS'][0]['password']}来获取重定向后的参数。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

大家都知道我们在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>
	$
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值