Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I prevent Spring 3.0 MVC @ModelAttribute variables from appearing in URL?
    primarykey
    data
    text
    <p>Using Spring MVC 3.0.0.RELEASE, I have the following Controller:</p> <pre><code>@Controller @RequestMapping("/addIntake.htm") public class AddIntakeController{ private final Collection&lt;String&gt; users; public AddIntakeController(){ users = new ArrayList&lt;String&gt;(); users.add("user1"); users.add("user2"); // ... users.add("userN"); } @ModelAttribute("users") public Collection&lt;String&gt; 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; } } </code></pre> <p>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.</p> <p>Everything works great, except for when I redirect to the intakeDetails.htm page, I get a URL that looks like this:</p> <p><code>http://localhost:8080/project/intakeDetails.htm?caseNumber=1&amp;users=user1&amp;users=user2&amp;users=user3&amp;users=user4...</code></p> <p>How do I prevent the user Collection from showing up in the URL? </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload