1、时间真快,一晃又快冬天了,下了第一场雪。雪花漫漫,堵车悠悠。

2、这次遇到这样一个问题,就是RedirectAttributes传递数据参数,如果参数数据过大,在IE8浏览器时候会跳转不过去。其实发现,很多时候都是IE8给我们找麻烦。因为在IE9以上还有谷歌等其他浏览器基本都是可以携带大量的长度的数据参数。所以之前的工程估计也是没有注意到这一点。

3、先上一个问题原型代码

@RequestMapping("/test1.do")
public String test1(HttpServletRequest request, HttpServletResponse response, RedirectAttributes attr) throws Exception { attr.addAttribute("content", 非常长的一串字符串,这里我就不写了哈,靠想象);
return "redirect:/test2.do";
} @RequestMapping("/test2.do")
public String test2(HttpServletRequest request, HttpServletResponse response) throws Exception { }

4、我们想要获取content参数的值,那么我想到了几种方法。

5、方法一,我们知道RedirectAttributes的addAttribute()方法其实是一种get方式,那么参数就会拼接到url上,这样IE8超过限制的长度,就无法跳转了。那么其实RedirectAttributes也给提供了另一种传参方式addFlashAttribute(),这个是相当月post方式,不会再地址栏上拼接参数,那么我们如何接收这种方式的参数呢。也有两个方案,接收方案一:

@RequestMapping("/test1.do")
public String test1(HttpServletRequest request, HttpServletResponse response, RedirectAttributes attr) throws Exception { attr.addFlashAttribute("content", 非常长的一串字符串,这里我就不写了哈,靠想象);
return "redirect:/test2.do";
} @RequestMapping("/test2.do")
public String test2(HttpServletRequest request, HttpServletResponse response,@RequestParam(value="content") String content) throws Exception {
String result = content;
}

6、方案一很容易发现是利用spring的注释方法@RequestParam(value="content") String content来获取的。但是有时候这种方法不方便使用,那么还有一个方案二:

@RequestMapping("/test1.do")
public String test1(HttpServletRequest request, HttpServletResponse response, RedirectAttributes attr) throws Exception { attr.addFlashAttribute("content", 非常长的一串字符串,这里我就不写了哈,靠想象);
return "redirect:/test2.do";
} @RequestMapping("/test2.do")
public String test2(HttpServletRequest request, HttpServletResponse response) throws Exception {
     //1.RequestContextUtils是spring提供的类。
Map<String, String> flashmap = (Map<String, String>) RequestContextUtils.getInputFlashMap(request);
String a = flashmap.get("content");
}

7、这个也是运用了spring的RequestContextUtils类获取到参数content

8、如果这两个方案都不方便使用,也有一种简单便捷的方式,就是利用session,不过这种方式要考虑并发高的时候session的影响,要根据场景来判断

@RequestMapping("/test1.do")
public String test1(HttpServletRequest request, HttpServletResponse response, RedirectAttributes attr) throws Exception { request.getSession().setAttribute("content", 非常长的一串字符串,这里我就不写了哈,靠想象);
return "redirect:/test2.do";
} @RequestMapping("/test2.do")
public String test2(HttpServletRequest request, HttpServletResponse response) throws Exception {
          //2.运用session 删除session
String content = (String) request.getSession().getAttribute("content");
request.getSession().removeAttribute("content");
}

9、好了,目前就想到了这几个方案,不知道能否帮助到各位,如果有好的方案也希望大家教我,谢谢

RedirectAttributes 之 IE8请求跳转失败的更多相关文章

  1. 为什么不能将客户端的连接请求跳转或转发到本机lo回环接口上?

    一.为什么不能将本机的请求跳转/转发到回环接口上? 如上图一样,服务器对外只开放了一个80端口,但是web服务监听在了lo 接口上8080端口上,现在要实现外网通过访问服务器的80端口,来提供web服 ...

  2. startActivity跳转失败而且没有异常信息

    startActivity跳转不能显示目标activity的布局(显示空白页),而且没有异常信息 onCreate()方法重写错误 应该重写的是onCreate(Bundle savedInstanc ...

  3. svn 提交错误 400 Bad Reqest MKACTIVITY 请求于XX失败 Conflict Unable to connect to a repository at URL

    思路来源:http://www.cnblogs.com/wangyt223/archive/2012/11/22/2782801.html svn 提交错误 400 Bad Reqest MKACTI ...

  4. DES加密与解密在GET请求时解密失败的问题

    DES加密与解密在GET请求时解密失败的问题 在数据进行加密后传递会更安全,但可能有个问题:就是Url编码问题,如果不对Url进行编码直接加密,那么在解密时,如果字符串存在 “+”,这种特殊符号,在解 ...

  5. 微信小程序页面-页面跳转失败WAService.js:3 navigateTo:fail url not in app.json

    微信小程序新建页面的要素一是新建的文件名称和其子文件的名称最好一致,不然容易出问题,在小程序页面跳转中如果出现WAService.js:3 navigateTo:fail url not in app ...

  6. App拉起小程序提示跳转失败

    App拉起小程序提示跳转失败 req.userName = "gh_8afldfalsejw"; // 小程序的原始ID,注意不是Appid

  7. 单点登录跳转失败(原因是 主票据申请子票据失败) asp.net 同站点下不同应用间不同版本Framework问题

    单点登录跳转失败(原因是 主票据申请子票据失败) asp.net 同站点下不同应用间不同版本Framework问题 今天遇到一个问题,在主站点现在配置的应用和主站点登录会话状态不能共享,进入子站点应用 ...

  8. 【Azure API 管理】APIM CORS策略设置后,跨域请求成功和失败的Header对比实验

    在文章"从微信小程序访问APIM出现200空响应的问题中发现CORS的属性[terminate-unmatched-request]功能"中分析了CORS返回空200的问题后,进一 ...

  9. Ajax发送POST请求SpringMVC页面跳转失败

    问题描述:因为使用的是SpringMVC框架,所以想使用ModelAndView进行页面跳转.思路是发送POST请求,然后controller层中直接返回相应ModelAndView,但是这种方法不可 ...

随机推荐

  1. JavaScript 小实例 - 表单输入内容检测,对页面的增删改

    JavaScript 小实例 - 表单输入内容检测,对页面的增删改 效果体验地址:https://xpwi.github.io/js/JavaScript01/jsForm.html 功能: 1.向页 ...

  2. 2.bootstrap安装

    1.下载 您可以从 http://getbootstrap.com/ 上下载 Bootstrap 的最新版本(或者 http://www.bootcss.com/  中文网) Download Boo ...

  3. 查询SQL Version详细信息

    下面是一个查询SQL Server版本并给出升级建议的SQL代码,用来学习写SQL代码. ------------------------------------------------------- ...

  4. 类型“Microsoft.Office.Interop.Word.ApplicationClass”错误 4317 无法嵌入互操作类型

    类型“Microsoft.Office.Interop.Word.ApplicationClass”错误 4317 无法嵌入互操作类型“Microsoft.Office.Interop.Word.Ap ...

  5. [翻译] AJProgressPanel

    AJProgressPanel Animated progress panel 可做动画的进度条 No images needed, all CoreGraphics code 不需要图片,使用Cor ...

  6. Java学习---Pinyin4j使用手册

    一般用法 pinyin4j的使用很方便,一般转换只需要使用PinyinHelper类的静态工具方法即可: String[] pinyin = PinyinHelper.toHanyuPinyinStr ...

  7. Git 解决方案 commit your changes or stash them before you can merge

    error: Your local changes to the following files would be overwritten by merge: *********** Please, ...

  8. Entity Framework:代码优先

    一.代码优先Code First EF6支持Oracle ODT 12C Release 3 (net4.5) DataModel(类)-->生成数据库DB 或 存在的数据库DB-->生成 ...

  9. Unable to perform unmarshalling at line number 16 and column 63 in RESOURCE hibernate.cfg.xml. Message: cvc-elt.1: 找不到元素 'hibernate-configuration' 的声明。

    七月 02, 2017 4:32:37 下午 org.hibernate.Version logVersionINFO: HHH000412: Hibernate Core {5.2.10.Final ...

  10. fpn

    class-aware detector 和 class-agnostic detector:https://blog.csdn.net/yeyang911/article/details/68484 ...