How do I prevent Spring 3.0 MVC @ModelAttribute variables from appearing in URL?
java, spring, spring-mvc
Solution
Since spring 3.1 the `RequestMappingHandlerAdapter` provides a flag called `ignoreDefaultModelOnRedirect`that you can use to prevent using the content of the defautl model if the controller redirects.
Problem
Using Spring MVC 3.0.0.RELEASE, I have the following Controller: ``` @Controller @RequestMapping("/addIntake.htm") public class AddIntakeController{ private final Collection<String> users; public AddIntakeController(){ users = new ArrayList<String>(); users.add("user1"); users.add("user2"); // ... users.add("userN"); } @ModelAttribute("users") public Collection<String> getUsers(){ return this.users; } @RequestMapping(method=RequestMethod.GET) public String setupForm(ModelMap model){ // Set up command object Intake intake = new Intake(); intake.setIntakeDate(new Date()); model.addAttribute("intake", intake); return "addIntake"; } @RequestMapping(method=RequestMethod.POST) public String addIntake(@ModelAttribute("intake")Intake intake, BindingResult result){ // Validate Intake command object and persist to database // ... String caseNumber = assignIntakeACaseNumber(); return "redirect:intakeDetails.htm?caseNumber=" + caseNumber; } } ``` The Controller reads Intake information from a command object populated from an HTML form, validates the command object, persists the information to the database, and returns a case number. Everything works great, except for when I redirect to the intakeDetails.htm page, I get a URL that looks like this: `http://localhost:8080/project/intakeDetails.htm?caseNumber=1&users=user1&users=user2&users=user3&users=user4...` How do I prevent the user Collection from showing up in the URL?