Hi there, In a typical Spring application you have the GET/POST/Redirect pattern. An example of this can be seen on the spring-eap6-quickstart project on github: https://github.com/openshift/spring-eap6-quickstart/blob/master/src/main/java/org/jboss/tools/example/springmvc/mvc/MemberController.java In the shown "registerNewMember" method a redirect is performed after successful registration. It is however furthermore possible to add some flash attributes in such a method by means of an injected RedirectAttributes object, thus the method could look like following: @RequestMapping(method=RequestMethod.POST) public String registerNewMember(@ModelAttribute("newMember") Member newMember, BindingResult result, Model model, RedirectAttributes redirectAttributes) { if (!result.hasErrors()) { memberDao.register(newMember); // Add flash attribute: redirectAttributes.addFlashAttribute("statusMessage","My Message"); return "redirect:/"; } ... } This is typically used to store a more complex object as a flash attribute which is automatically added to the model and can be accessed in the redirected method (what Spring does under the hood is, that it stores such a flash attribute in session and deletes it immediately when it is retrieved in the redirected method: @RequestMapping(method=RequestMethod.GET) public String displaySortedMembers(Model model, HttpServletRequest request) { // "statusMessage" is automaically added to the model // This can also be verified by using RequestContextUtils: Map<String, ?> map = RequestContextUtils.getInputFlashMap(request); LOGGER.warn("Receive flash map with {} elements", (map != null ? map.size() : 0)); if (map != null) { Object statusMessage = map.get("statusMessage"); LOGGER.warn("Received statusMessage attribute {}", statusMessage); } // End check for passed flash attributes... here is the original code: model.addAttribute("newMember", new Member()); model.addAttribute("members", memberDao.findAllOrderedByName()); return "index"; } The problem now is that the "statusMessage" flash attribute is not there on openshift, it seems as it is lost during the request (I verified this by means of the shown RequestContextUtils check): The flash map has in fact no single entry! If I run the code on my local Tomcat it works however, and this is also the recommended way to do this (you can check this on the basis of plenty of tutorials in the web. Therefore I assume that this may be a bug in the openshift platform? I used the Tomcat 6 cartridge on openshift (I used Spring in version 3.1.1.RELEASE). Hope I clarified the issue. Best regards, Clemens
Created attachment 871170 [details] sample application that does flashes w/ redirect
This appears to be working for me, I've attached the contents of my app's repository. You can also observe it here: http://springos-bparees.rhcloud.com ("My Message" in the final page is coming from the flash attribute set on the initial request, per your example). You can also see the println output in catalina.out after hitting the app.
Hi Ben, Thank you for the quick answer! I did a more detailed investigation of my code (and I additionally created some plain examples which also worked for me) and I finally found the quite subtle problem: In my code I dynamically constructed the Spring redirect URL with two leading '/'. Example: "redirect://mypage/foo/bar". With this URL I got in fact redirected to the specified URL without any error, but on Openshift my flash attrbiutes were lost (on my local tomcat this worked however as I mentioned in my entry post). So after fixing the problem by means of removing the double '/' (redirect url looks now like this: "redirect:/mypage/foo/bar") it works now also on Openshift. Anyway a quite strange and subtle behaviour :-) Best regards, Clemens